3 using System.Reflection;
6 public class MyAttribute: Attribute {
8 public MyAttribute (string stuff) {
9 System.Console.WriteLine (stuff);
13 public class My2Attribute: MyAttribute {
15 public My2Attribute (string stuff, int blah) : base (stuff) {
16 System.Console.WriteLine ("ctor with int val"+stuff);
21 public class My3Attribute : Attribute {
36 class XAttribute : Attribute {
39 throw new Exception ("X");
43 interface ZInterface {
46 class ZAttribute : Attribute, ZInterface {
54 [My2("testclass", 22)]
55 [My3(Prop = new char [] { 'A', 'B', 'C', 'D' }, Prop2 = new char [] { 'A', 'D' })]
57 static public int Main() {
58 System.Reflection.MemberInfo info = typeof (Test);
59 object[] attributes = info.GetCustomAttributes (false);
60 for (int i = 0; i < attributes.Length; i ++) {
61 System.Console.WriteLine(attributes[i]);
63 if (attributes.Length != 3)
65 for (int i = 0; i < attributes.Length; ++i) {
66 if (attributes [i] is MyAttribute) {
67 if (((MyAttribute)attributes [i]).val != "testclass")
70 if (attributes [i] is My3Attribute) {
71 if (new String (((My3Attribute)attributes [i]).Prop) != "ABCD") {
72 Console.WriteLine (new String (((My3Attribute)attributes [i]).Prop));
75 if (new String (((My3Attribute)attributes [i]).Prop2) != "AD") {
76 Console.WriteLine (new String (((My3Attribute)attributes [i]).Prop2));
83 // Test that requesting a specific custom attributes does not
84 // create all the others
87 typeof (Y).IsDefined (typeof (ZAttribute), true);
88 typeof (Y).IsDefined (typeof (XAttribute), true);
90 typeof (Y).GetCustomAttributes (typeof (ZAttribute), true);
93 typeof (Y).GetCustomAttributes (true);
99 if (typeof (Y).GetCustomAttributes (typeof (ZInterface), true).Length != 1)