2002-07-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / errors / cs-20.cs
1 // cs-20.cs : Cannot find attribute type My (maybe you forgot to set the usage using the AttributeUsage attribute ?).
2 // Line : 18
3
4 using System;
5 using System.Reflection;
6
7 namespace Test {
8         
9         //[AttributeUsage (AttributeTargets.All)]
10         public class MyAttribute: Attribute {
11                 public string val;
12                 public MyAttribute (string stuff) {
13                         System.Console.WriteLine (stuff);
14                         val = stuff;
15                 }
16         }
17         
18         [My("testclass")]
19
20         public class Test {
21                 static public int Main() {
22                         System.Reflection.MemberInfo info = typeof (Test);
23                         object[] attributes = info.GetCustomAttributes (false);
24                         for (int i = 0; i < attributes.Length; i ++) {
25                                 System.Console.WriteLine(attributes[i]);
26                         }
27                         if (attributes.Length != 2)
28                                 return 1;
29                         MyAttribute attr = (MyAttribute) attributes [0];
30                         if (attr.val != "testclass")
31                                 return 2;
32                         return 0;
33                 }
34         }
35 }