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 {
53 [My("arg\0string\0with\0nuls")]
58 [My2("testclass", 22)]
59 [My3(Prop = new char [] { 'A', 'B', 'C', 'D' }, Prop2 = new char [] { 'A', 'D' })]
61 static public int Main() {
62 System.Reflection.MemberInfo info = typeof (Test);
63 object[] attributes = info.GetCustomAttributes (false);
64 for (int i = 0; i < attributes.Length; i ++) {
65 System.Console.WriteLine(attributes[i]);
67 if (attributes.Length != 3)
69 for (int i = 0; i < attributes.Length; ++i) {
70 if (attributes [i] is MyAttribute) {
71 if (((MyAttribute)attributes [i]).val != "testclass")
74 if (attributes [i] is My3Attribute) {
75 if (new String (((My3Attribute)attributes [i]).Prop) != "ABCD") {
76 Console.WriteLine (new String (((My3Attribute)attributes [i]).Prop));
79 if (new String (((My3Attribute)attributes [i]).Prop2) != "AD") {
80 Console.WriteLine (new String (((My3Attribute)attributes [i]).Prop2));
87 // Test that requesting a specific custom attributes does not
88 // create all the others
91 typeof (Y).IsDefined (typeof (ZAttribute), true);
92 typeof (Y).IsDefined (typeof (XAttribute), true);
94 typeof (Y).GetCustomAttributes (typeof (ZAttribute), true);
97 typeof (Y).GetCustomAttributes (true);
103 if (typeof (Y).GetCustomAttributes (typeof (ZInterface), true).Length != 1)
106 if (!typeof (Y).IsDefined (typeof (ZInterface), true))
109 // Test that synthetic methods have no attributes
110 if (typeof(int[,]).GetConstructor (new Type [] { typeof (int), typeof (int) }).GetCustomAttributes (true).Length != 0)
113 // Test that nuls are preserved (see Xamarin bug 5732)
114 if (((MyAttribute)typeof (NulTests).GetCustomAttributes (true)[0]).val != "arg\0string\0with\0nuls")