2003-12-28 Ben Maurer <bmaurer@users.sourceforge.net>
[mono.git] / mcs / tests / test-102.cs
1 using System;
2 using System.Reflection;
3
4 [assembly: AssemblyTitle ("Foo")]
5 [assembly: AssemblyVersion ("1.0.2")]
6
7 namespace N1 {
8                 
9         [AttributeUsage (AttributeTargets.All)]
10         public class MineAttribute : Attribute {
11
12                 public string name;
13                 
14                 public MineAttribute (string s)
15                 {
16                         name = s;
17                 }
18         }
19
20         [AttributeUsage (AttributeTargets.ReturnValue)]
21         public class ReturnAttribute : Attribute {
22
23                 public string name;
24                 
25                 public ReturnAttribute (string s)
26                 {
27                         name = s;
28                 }
29         }
30
31         interface A {
32                 [Mine ("hello")]
33                 void Hello ();
34         }       
35
36         public class Foo {      
37                 
38                 int i;
39                 
40                 [Mine ("Foo")]
41                 [return: Return ("Bar")]        
42                 public static int Main ()
43                 {
44                         Type t = typeof (Foo);
45                         foreach (MemberInfo m in t.GetMembers ()){
46                                 if (m.Name == "Main"){
47                                         MethodInfo mb = (MethodInfo) m;
48
49                                         ICustomAttributeProvider p = mb.ReturnTypeCustomAttributes;
50                                         object [] ret_attrs = p.GetCustomAttributes (false);
51
52                                         if (ret_attrs.Length != 1){
53                                                 Console.WriteLine ("Got more than one return attribute");
54                                                 return 1;
55                                         }
56                                         if (!(ret_attrs [0] is ReturnAttribute)){
57                                                 Console.WriteLine ("Dit not get a MineAttribute");
58                                                 return 2;
59                                         }
60
61                                         ReturnAttribute ma = (ReturnAttribute) ret_attrs [0];
62                                         if (ma.name != "Bar"){
63                                                 Console.WriteLine ("The return attribute is not Bar");
64                                                 return 2;
65                                         }
66                                 }
67                         }
68
69                         return 0;
70                 }
71         }
72 }