2 using System.Reflection;
4 [assembly: AssemblyTitle ("Foo")]
5 [assembly: AssemblyVersion ("1.0.2")]
9 [AttributeUsage (AttributeTargets.All)]
10 public class MineAttribute : Attribute {
14 public MineAttribute (string s)
20 [AttributeUsage (AttributeTargets.ReturnValue)]
21 public class ReturnAttribute : Attribute {
25 public ReturnAttribute (string s)
31 public interface TestInterface {
32 void Hello ([Mine ("param")] int i);
40 [return: Return ("Bar")]
41 public static int Main ()
43 Type t = typeof (Foo);
44 foreach (MemberInfo m in t.GetMembers ()){
45 if (m.Name == "Main"){
46 MethodInfo mb = (MethodInfo) m;
48 ICustomAttributeProvider p = mb.ReturnTypeCustomAttributes;
49 object [] ret_attrs = p.GetCustomAttributes (false);
51 if (ret_attrs.Length != 1){
52 Console.WriteLine ("Got more than one return attribute");
55 if (!(ret_attrs [0] is ReturnAttribute)){
56 Console.WriteLine ("Dit not get a MineAttribute");
60 ReturnAttribute ma = (ReturnAttribute) ret_attrs [0];
61 if (ma.name != "Bar"){
62 Console.WriteLine ("The return attribute is not Bar");
68 Type ifType = typeof (TestInterface);
70 MethodInfo method = ifType.GetMethod ("Hello",
71 BindingFlags.Public | BindingFlags.Instance);
73 ParameterInfo[] parameters = method.GetParameters();
74 ParameterInfo param = parameters [0];
76 object[] testAttrs = param.GetCustomAttributes (true);
78 if (testAttrs.Length != 1)