[corlib] Simplify RuntimeInformation by getting OS name from the runtime (#13164)
[mono-project.git] / mcs / tests / test-254.cs
blob36453ea86b397061250c48d9d7b086bc1dca1d8d
1 using System;
2 using System.Reflection;
3 using System.Runtime.CompilerServices;
5 [assembly: Test]
7 namespace N
11 [AttributeUsage(AttributeTargets.All)]
12 public class TestAttribute: Attribute
16 public class Test_1
18 [return: Test]
19 public void Test (int a)
24 [return: Test]
25 public delegate Delegate test_delegate(int i);
28 public class Test_2
30 public int Test
32 [return: Test]
33 get {
34 return 4;
37 [return: Test]
38 set {
42 public bool Test2
44 [param: Test]
45 set {}
49 public class Test_3
51 [field: Test]
52 public event test_delegate e_1;
54 [method: Test]
55 public event test_delegate e_2;
58 public class Test_4
60 // TODO: Where to apply ?
62 [event: Test]
63 public event test_delegate e_1 {
64 add {}
65 remove {}
68 public event test_delegate e_2 {
69 [return: Test]
70 add {}
71 [return: Test]
72 remove {}
75 public event test_delegate e_3 {
76 [param: Test]
77 add {}
78 [param: Test]
79 remove {}
84 public class ClassMain
86 static bool failed = false;
88 static void Assert (object[] attrs, bool expected_presence, int tc)
90 if (attrs.Length == 1 && expected_presence)
91 return;
93 if (!expected_presence && attrs.Length == 0)
94 return;
96 Console.WriteLine ("#" + tc.ToString () + " failed");
97 failed = true;
100 public static int Main () {
101 MethodInfo mi = typeof (Test_1).GetMethod ("Test");
102 Assert (mi.GetParameters ()[0].GetCustomAttributes (true), false, 1);
103 Assert (mi.GetCustomAttributes (true), false, 2);
104 Assert (mi.ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 3);
106 mi = typeof (test_delegate).GetMethod ("Invoke");
107 Assert (mi.GetParameters ()[0].GetCustomAttributes (true), false, 4);
108 Assert (mi.GetCustomAttributes (true), false, 5);
109 Assert (mi.ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 6);
111 /* Under net 2.0, SerializableAttribute is returned */
112 if (typeof (test_delegate).GetCustomAttributes (false).Length != 1)
113 Assert (typeof (test_delegate).GetCustomAttributes (false), false, 7);
115 PropertyInfo pi = typeof (Test_2).GetProperty ("Test");
116 Assert (pi.GetCustomAttributes (true), false, 31);
117 Assert (pi.GetGetMethod ().GetCustomAttributes (true), false, 32);
118 Assert (pi.GetGetMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 33);
119 Assert (pi.GetSetMethod ().GetCustomAttributes (true), false, 34);
120 Assert (pi.GetSetMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 35);
121 pi = typeof (Test_2).GetProperty ("Test2");
122 Assert (pi.GetCustomAttributes (true), false, 36);
123 Assert (pi.GetSetMethod ().GetCustomAttributes (true), false, 37);
124 Assert (pi.GetSetMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 38);
125 Assert (pi.GetSetMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 39);
127 EventInfo ei = typeof(Test_3).GetEvent ("e_1");
128 Assert (ei.GetCustomAttributes (true), false, 41);
129 Assert (ei.GetAddMethod ().GetCustomAttributes (true), false, 42);
130 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 43);
131 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 44);
132 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 45);
133 FieldInfo fi = typeof(Test_3).GetField ("e_1", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
134 Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 46);
135 Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), true, 47);
137 ei = typeof(Test_3).GetEvent ("e_2");
138 Assert (ei.GetCustomAttributes (true), false, 51);
139 Assert (ei.GetAddMethod ().GetCustomAttributes (true), true, 52);
140 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 53);
141 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), true, 54);
142 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 55);
143 fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
144 Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 56);
145 Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), false, 57);
147 ei = typeof(Test_4).GetEvent ("e_2");
148 Assert (ei.GetCustomAttributes (true), false, 71);
149 Assert (ei.GetAddMethod ().GetCustomAttributes (true), false, 72);
150 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 73);
151 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 74);
152 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 75);
153 fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
154 Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 76);
155 Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), false, 77);
157 ei = typeof(Test_4).GetEvent ("e_3");
158 Assert (ei.GetCustomAttributes (true), false, 81);
159 Assert (ei.GetAddMethod ().GetCustomAttributes (true), false, 82);
160 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 83);
161 Assert (ei.GetAddMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 84);
162 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 85);
163 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 86);
164 Assert (ei.GetRemoveMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 87);
165 fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
166 Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 86);
167 Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), false, 87);
169 return failed ? 1 : 0;