Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / delegate12.cs
1 using System;
2
3 class MainClass
4 {
5         public static int Main(string[] args)
6         {
7                 DerivedClass o = new DerivedClass();
8
9                 Func<string> del1 = GetDel1 (o);
10                 Func<string> del2 = GetDel2 (o);
11
12
13                 Console.WriteLine("Action\n======\nReflected type: {0}\nDeclaring type: {1}\nAttributes: {2}\nResult: {3}",
14                         del1.Method.ReflectedType, del1.Method.DeclaringType, del1.Method.Attributes, del1 ());
15
16                 Console.WriteLine ();
17
18                 Console.WriteLine("Delegate\n========\nReflected type: {0}\nDeclaring type: {1}\nAttributes: {2}\nResult: {3}",
19                         del2.Method.ReflectedType, del2.Method.DeclaringType, del2.Method.Attributes, del2 ());
20
21                 if (del1.Method.ReflectedType != typeof (DerivedClass))
22                         return 10;
23                 if (del1.Method.DeclaringType != typeof (DerivedClass))
24                         return 11;
25                 if (del1 () != "Derived method")
26                         return 12;
27
28                 if (del2.Method.ReflectedType != typeof (DerivedClass))
29                         return 20;
30                 if (del2.Method.DeclaringType != typeof (DerivedClass))
31                         return 21;
32                 if (del2 () != "Derived method")
33                         return 22;
34
35                 if (!del1.Equals (del2))
36                         return 30;
37                 if (!del2.Equals (del1))
38                         return 31;
39
40                 return 0;
41         }
42
43         static Func<string> GetDel1 (DerivedClass o)
44         {
45                 return o.GetMethod();
46         }
47
48         static Func<string> GetDel2 (DerivedClass o)
49         {
50                 return (Func<string>) Delegate.CreateDelegate(typeof(Func<string>), o, o.GetMethod().Method);
51         }
52 }
53
54 class BaseClass
55 {
56         public Func<string> GetMethod()
57         {
58                 return MyMethod;
59         }
60
61         public virtual string MyMethod()
62         {
63                 return "Base method";
64         }
65 }
66
67 class DerivedClass : BaseClass
68 {
69         public override string MyMethod()
70         {
71                 return "Derived method";
72         }
73 }