[System] Tweak socket test
[mono-project.git] / mono / tests / generic-delegate2.2.cs
blob672388f97a0c0b1bb98b6bd68e33a12e020cc753
1 using System;
2 using System.Reflection;
4 /*
5 public delegate object ArrDel (int i);
7 public class Gen<T> {
8 public object newArr (int i) {
9 return new T [i];
12 public ArrDel newDel () {
13 return new ArrDel (this.newArr);
17 public delegate object DelObj (object g, int i);
18 public delegate object DelStr (object g, int i);
21 public class main {
22 public static int work () {
23 Gen<string> gs = new Gen<string> ();
24 Gen<object> go = new Gen<object> ();
26 MethodInfo miObj = typeof (Gen<object>).GetMethod ("newArr", BindingFlags.Public | BindingFlags.Instance);
27 MethodInfo miStr = typeof (Gen<string>).GetMethod ("newArr", BindingFlags.Public | BindingFlags.Instance);
29 if (miObj == miStr) {
30 Console.WriteLine ("methods equal");
31 return 1;
34 ObjArrDel oad = go.newObjDel ();
35 StrArrDel sad = gs.newStrDel ();
36 StrArrDel sad2 = (StrArrDel)Delegate.CreateDelegate (typeof (StrArrDel), null, miStr);
38 if (oad.Method != miObj) {
39 Console.WriteLine ("wrong object method");
40 if (oad.Method == miStr)
41 Console.WriteLine ("object method is string");
42 return 1;
45 if (sad.Method != miStr) {
46 Console.WriteLine ("wrong string method");
47 if (sad.Method == miObj)
48 Console.WriteLine ("string method is object");
49 else
50 return 1;
51 } else {
52 Console.WriteLine ("right string method");
55 if (sad2.Method != miStr) {
56 Console.WriteLine ("wrong string2 method");
57 if (sad2.Method == miObj)
58 Console.WriteLine ("string2 method is object");
59 return 1;
62 Console.WriteLine ("calling object del");
63 if (oad (go, 3).GetType () != typeof (object [])) {
64 Console.WriteLine ("not object array");
65 return 1;
68 Console.WriteLine ("calling string del");
69 if (sad (gs, 3).GetType () != typeof (string [])) {
70 Console.WriteLine ("not string array");
71 return 1;
74 Console.WriteLine ("calling string del2");
75 if (sad2 (gs, 3).GetType () != typeof (string [])) {
76 Console.WriteLine ("not string2 array");
77 return 1;
80 try {
81 StrArrDel sad3 = (StrArrDel)Delegate.CreateDelegate (typeof (StrArrDel), null, miObj);
82 Console.WriteLine ("object method for string delegate");
83 return 1;
84 } catch (ArgumentException) {
88 DelObj delObj = (DelObj)Delegate.CreateDelegate (typeof (DelObj), null, miObj);
90 if (delObj (go, 3).GetType () != typeof (object []))
91 return 1;
93 DelStr delStr = (DelStr)Delegate.CreateDelegate (typeof (DelStr), null, miStr);
95 if (delStr (gs, 3).GetType () != typeof (string []))
96 return 1;
100 ArrDel ad = go.newDel ();
101 if (ad (3).GetType () != typeof (object []))
102 return 1;
104 ad = gs.newDel ();
105 if (ad (3).GetType () != typeof (string []))
106 return 1;
109 Console.WriteLine ("done");
111 return 0;
114 public static int Main () {
115 Gen<string> gs = new Gen<string> ();
116 Gen<object> go = new Gen<object> ();
118 gs.newArr (3);
119 go.newArr (3);
121 return work ();