2 using System.Reflection;
10 [AttributeUsage(AttributeTargets.All)]
11 public class TestAttribute: Attribute
18 public void Test (int a)
24 public delegate Delegate test_delegate(int i);
51 public event test_delegate e_1;
54 public event test_delegate e_2;
59 // TODO: Where to apply ?
62 public event test_delegate e_1 {
67 public event test_delegate e_2 {
74 public event test_delegate e_3 {
83 public class ClassMain
85 static bool failed = false;
87 static void Assert (object[] attrs, bool expected_presence, int tc)
89 if (attrs.Length == 1 && expected_presence)
92 if (!expected_presence && attrs.Length == 0)
95 Console.WriteLine ("#" + tc.ToString () + " failed");
99 public static int Main () {
100 MethodInfo mi = typeof (Test_1).GetMethod ("Test");
101 Assert (mi.GetParameters ()[0].GetCustomAttributes (true), false, 1);
102 Assert (mi.GetCustomAttributes (true), false, 2);
103 Assert (mi.ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 3);
105 mi = typeof (test_delegate).GetMethod ("Invoke");
106 Assert (mi.GetParameters ()[0].GetCustomAttributes (true), false, 4);
107 Assert (mi.GetCustomAttributes (true), false, 5);
108 Assert (mi.ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 6);
109 Assert (typeof (test_delegate).GetCustomAttributes (false), false, 7);
111 PropertyInfo pi = typeof (Test_2).GetProperty ("Test");
112 Assert (pi.GetCustomAttributes (true), false, 31);
113 Assert (pi.GetGetMethod ().GetCustomAttributes (true), false, 32);
114 Assert (pi.GetGetMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 33);
115 Assert (pi.GetSetMethod ().GetCustomAttributes (true), false, 34);
116 Assert (pi.GetSetMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 35);
117 pi = typeof (Test_2).GetProperty ("Test2");
118 Assert (pi.GetCustomAttributes (true), false, 36);
119 Assert (pi.GetSetMethod ().GetCustomAttributes (true), false, 37);
120 Assert (pi.GetSetMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 38);
121 Assert (pi.GetSetMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 39);
123 EventInfo ei = typeof(Test_3).GetEvent ("e_1");
124 Assert (ei.GetCustomAttributes (true), false, 41);
125 Assert (ei.GetAddMethod ().GetCustomAttributes (true), false, 42);
126 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 43);
127 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 44);
128 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 45);
129 FieldInfo fi = typeof(Test_3).GetField ("e_1", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
130 Assert (fi.GetCustomAttributes (true), true, 46);
132 ei = typeof(Test_3).GetEvent ("e_2");
133 Assert (ei.GetCustomAttributes (true), false, 51);
134 Assert (ei.GetAddMethod ().GetCustomAttributes (true), true, 52);
135 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 53);
136 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), true, 54);
137 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 55);
138 fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
139 Assert (fi.GetCustomAttributes (true), false, 56);
141 ei = typeof(Test_4).GetEvent ("e_2");
142 Assert (ei.GetCustomAttributes (true), false, 71);
143 Assert (ei.GetAddMethod ().GetCustomAttributes (true), false, 72);
144 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 73);
145 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 74);
146 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 75);
147 fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
148 Assert (fi.GetCustomAttributes (true), false, 76);
150 ei = typeof(Test_4).GetEvent ("e_3");
151 Assert (ei.GetCustomAttributes (true), false, 81);
152 Assert (ei.GetAddMethod ().GetCustomAttributes (true), false, 82);
153 Assert (ei.GetAddMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 83);
154 Assert (ei.GetAddMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 84);
155 Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 85);
156 Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 86);
157 Assert (ei.GetRemoveMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 87);
158 fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
159 Assert (fi.GetCustomAttributes (true), false, 88);
161 return failed ? 1 : 0;