Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / invoke2.cs
1 using System;
2 using System.Reflection;
3
4 class B {
5         public virtual int vmethod () {
6                 return 0;
7         }
8 }
9
10 class T : B {
11
12         public override int vmethod () {
13                 return 1;
14         }
15         static int stuff (int a) {
16                 return 0;
17         }
18         static int stuff (char a) {
19                 return 1;
20         }
21         static int Main () {
22                 Type t = typeof (T);
23                 Type b = typeof (B);
24                 T obj = new T ();
25                 Type[] char_types = new Type[1] {typeof(char)};
26                 Type[] int_types = new Type[1] {typeof(int)};
27                 object[] int_args = new object[1] {1};
28                 object[] char_args = new object[1] {(char)1};
29                 MethodBase m1, m2;
30                 bool ok = false;
31                 try {
32                         m1 = t.GetMethod ("stuff", BindingFlags.Static|BindingFlags.NonPublic);
33                 } catch (AmbiguousMatchException) {
34                         ok = true;
35                 }
36                 if (!ok)
37                         return 1;
38
39                 m1 = t.GetMethod ("stuff", BindingFlags.Static|BindingFlags.NonPublic,
40                         null, char_types, null);
41                 Console.WriteLine ("m1: {0}", m1);
42                 if (m1 == null)
43                         return 2;
44
45                 object m1res = m1.Invoke (null, char_args);
46                 Console.WriteLine ("m1 invoke: {0}", m1res);
47                 if ((int)m1res != 1)
48                         return 3;
49                 
50                 ok = false;
51                 try {
52                         m1res = m1.Invoke (null, int_args);
53                 } catch (ArgumentException) {
54                         ok = true;
55                 }
56                 if (!ok)
57                         return 4;
58                 
59                 m2 = b.GetMethod ("vmethod");
60                 Console.WriteLine ("m2: {0}, declaring: {1}, reflected: {2}", m2, m2.DeclaringType, m2.ReflectedType);
61                 object m2res = m2.Invoke (obj, null);
62                 if ((int)m1res != 1)
63                         return 5;
64
65                 return 0;
66         }
67 }
68