2008-12-24 Mark Probst <mark.probst@gmail.com>
[mono.git] / mono / tests / custom-attr.cs
index 4105f244bfbfb041c350b9c4f3f42f63b3222260..40dbae17ddb9c93060eeef27c4b87577892b720a 100644 (file)
@@ -29,11 +29,30 @@ namespace Test {
                                array_val = value;
                        }
                }
+
+               public char[] Prop2;
+       }
+
+       class XAttribute : Attribute {
+               public XAttribute () 
+               {
+                       throw new Exception ("X");
+               }
+       }
+
+       interface ZInterface {
+    }
+
+       class ZAttribute : Attribute, ZInterface {
+       }
+
+       [X, Z, Serializable]
+       class Y {
        }
                        
        [My("testclass")]
        [My2("testclass", 22)]
-       [My3(Prop = new char [] { 'A', 'B', 'C' })]
+       [My3(Prop = new char [] { 'A', 'B', 'C', 'D' }, Prop2 = new char [] { 'A', 'D' })]
        public class Test {
                static public int Main() {
                        System.Reflection.MemberInfo info = typeof (Test);
@@ -49,10 +68,37 @@ namespace Test {
                                                return 2;
                                }
                                if (attributes [i] is My3Attribute) {
-                                       if (new String (((My3Attribute)attributes [i]).Prop) != "ABC")
+                                       if (new String (((My3Attribute)attributes [i]).Prop) != "ABCD") {
+                                               Console.WriteLine (new String (((My3Attribute)attributes [i]).Prop));
                                                return 3;
+                                       }
+                                       if (new String (((My3Attribute)attributes [i]).Prop2) != "AD") {
+                                               Console.WriteLine (new String (((My3Attribute)attributes [i]).Prop2));
+                                               return 4;
+                                       }
                                }
                        }
+
+                       //
+                       // Test that requesting a specific custom attributes does not
+                       // create all the others
+                       //
+
+                       typeof (Y).IsDefined (typeof (ZAttribute), true);
+                       typeof (Y).IsDefined (typeof (XAttribute), true);
+
+                       typeof (Y).GetCustomAttributes (typeof (ZAttribute), true);
+
+                       try {
+                               typeof (Y).GetCustomAttributes (true);
+                               return 4;
+                       }
+                       catch {
+                       }
+
+                       if (typeof (Y).GetCustomAttributes (typeof (ZInterface), true).Length != 1)
+                               return 5;
+
                        return 0;
                }
        }