[System] Tweak socket test
[mono-project.git] / mono / tests / invoke2.cs
blob3dbf927efb4e7ca6b626513cafdb9658520c0db9
1 using System;
2 using System.Reflection;
4 class B {
5 public virtual int vmethod () {
6 return 0;
10 class T : B {
12 public override int vmethod () {
13 return 1;
15 static int stuff (int a) {
16 return 0;
18 static int stuff (char a) {
19 return 1;
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;
36 if (!ok)
37 return 1;
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;
45 object m1res = m1.Invoke (null, char_args);
46 Console.WriteLine ("m1 invoke: {0}", m1res);
47 if ((int)m1res != 1)
48 return 3;
50 ok = false;
51 try {
52 m1res = m1.Invoke (null, int_args);
53 } catch (ArgumentException) {
54 ok = true;
56 if (!ok)
57 return 4;
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;
65 return 0;