2004-06-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mono / tests / custom-attr.cs
1
2 using System;
3 using System.Reflection;
4
5 namespace Test {
6         public class MyAttribute: Attribute {
7                 public string val;
8                 public MyAttribute (string stuff) {
9                         System.Console.WriteLine (stuff);
10                         val = stuff;
11                 }
12         }
13         public class My2Attribute: MyAttribute {
14                 public int ival;
15                 public My2Attribute (string stuff, int blah) : base (stuff) {
16                         System.Console.WriteLine ("ctor with int val"+stuff);
17                         ival = blah;
18                 }
19         }
20
21         public class My3Attribute : Attribute {
22                 char[] array_val;
23
24                 public char[] Prop {
25                         get {
26                                 return array_val;
27                         }
28                         set {
29                                 array_val = value;
30                         }
31                 }
32         }
33                         
34         [My("testclass")]
35         [My2("testclass", 22)]
36         [My3(Prop = new char [] { 'A', 'B', 'C' })]
37         public class Test {
38                 static public int Main() {
39                         System.Reflection.MemberInfo info = typeof (Test);
40                         object[] attributes = info.GetCustomAttributes (false);
41                         for (int i = 0; i < attributes.Length; i ++) {
42                                 System.Console.WriteLine(attributes[i]);
43                         }
44                         if (attributes.Length != 3)
45                                 return 1;
46                         for (int i = 0; i < attributes.Length; ++i) {
47                                 if (attributes [i] is MyAttribute) {
48                                         if (((MyAttribute)attributes [i]).val != "testclass")
49                                                 return 2;
50                                 }
51                                 if (attributes [i] is My3Attribute) {
52                                         if (new String (((My3Attribute)attributes [i]).Prop) != "ABC")
53                                                 return 3;
54                                 }
55                         }
56                         return 0;
57                 }
58         }
59 }