Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-102.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c82586d3530ec41798fb2201b931603eb123335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Reflection;

[assembly: AssemblyTitle ("Foo")]
[assembly: AssemblyVersion ("1.0.2")]

namespace N1 {
		
	[AttributeUsage (AttributeTargets.All)]
	public class MineAttribute : Attribute {

		public string name;
		
		public MineAttribute (string s)
		{
			name = s;
		}
	}

        [AttributeUsage (AttributeTargets.ReturnValue)]
	public class ReturnAttribute : Attribute {

		public string name;
		
		public ReturnAttribute (string s)
		{
			name = s;
		}
	}

	public interface TestInterface {
		void Hello ([Mine ("param")] int i);
	}	

	public class Foo {	
		
		int i;
		
		[Mine ("Foo")]
		[return: Return ("Bar")]	
		public static int Main ()
		{
			Type t = typeof (Foo);
			foreach (MemberInfo m in t.GetMembers ()){
				if (m.Name == "Main"){
					MethodInfo mb = (MethodInfo) m;

					ICustomAttributeProvider p = mb.ReturnTypeCustomAttributes;
					object [] ret_attrs = p.GetCustomAttributes (false);

					if (ret_attrs.Length != 1){
						Console.WriteLine ("Got more than one return attribute");
						return 1;
					}
					if (!(ret_attrs [0] is ReturnAttribute)){
						Console.WriteLine ("Dit not get a MineAttribute");
						return 2;
					}

					ReturnAttribute ma = (ReturnAttribute) ret_attrs [0];
					if (ma.name != "Bar"){
						Console.WriteLine ("The return attribute is not Bar");
						return 2;
					}
				}
			}

                        Type ifType = typeof (TestInterface);
                        
                        MethodInfo method = ifType.GetMethod ("Hello", 
                                                              BindingFlags.Public | BindingFlags.Instance);
                        
                        ParameterInfo[] parameters = method.GetParameters();
                        ParameterInfo param = parameters [0];
                        
                        object[] testAttrs = param.GetCustomAttributes (true);
                        
                        if (testAttrs.Length != 1)
                                return 1;
                        
			return 0;
		}
	}
}