Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / generic-delegate2.2.cs
1 using System;
2 using System.Reflection;
3
4 /*
5 public delegate object ArrDel (int i);
6
7 public class Gen<T> {
8     public object newArr (int i) {
9         return new T [i];
10     }
11
12     public ArrDel newDel () {
13         return new ArrDel (this.newArr);
14     }
15 }
16
17 public delegate object DelObj (object g, int i);
18 public delegate object DelStr (object g, int i);
19 */
20
21 public class main {
22     public static int work () {
23         Gen<string> gs = new Gen<string> ();
24         Gen<object> go = new Gen<object> ();
25
26         MethodInfo miObj = typeof (Gen<object>).GetMethod ("newArr", BindingFlags.Public | BindingFlags.Instance);
27         MethodInfo miStr = typeof (Gen<string>).GetMethod ("newArr", BindingFlags.Public | BindingFlags.Instance);
28
29         if (miObj == miStr) {
30             Console.WriteLine ("methods equal");
31             return 1;
32         }
33
34         ObjArrDel oad = go.newObjDel ();
35         StrArrDel sad = gs.newStrDel ();
36         StrArrDel sad2 = (StrArrDel)Delegate.CreateDelegate (typeof (StrArrDel), null, miStr);
37
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;
43         }
44
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");
53         }
54
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;
60         }
61
62         Console.WriteLine ("calling object del");
63         if (oad (go, 3).GetType () != typeof (object [])) {
64             Console.WriteLine ("not object array");
65             return 1;
66         }
67
68         Console.WriteLine ("calling string del");
69         if (sad (gs, 3).GetType () != typeof (string [])) {
70             Console.WriteLine ("not string array");
71             return 1;
72         }
73
74         Console.WriteLine ("calling string del2");
75         if (sad2 (gs, 3).GetType () != typeof (string [])) {
76             Console.WriteLine ("not string2 array");
77             return 1;
78         }
79
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) {
85         }
86
87         /*
88         DelObj delObj = (DelObj)Delegate.CreateDelegate (typeof (DelObj), null, miObj);
89
90         if (delObj (go, 3).GetType () != typeof (object []))
91             return 1;
92
93         DelStr delStr = (DelStr)Delegate.CreateDelegate (typeof (DelStr), null, miStr);
94
95         if (delStr (gs, 3).GetType () != typeof (string []))
96             return 1;
97         */
98
99         /*
100         ArrDel ad = go.newDel ();
101         if (ad (3).GetType () != typeof (object []))
102             return 1;
103
104         ad = gs.newDel ();
105         if (ad (3).GetType () != typeof (string []))
106             return 1;
107         */
108
109         Console.WriteLine ("done");
110
111         return 0;
112     }
113
114     public static int Main () {
115         Gen<string> gs = new Gen<string> ();
116         Gen<object> go = new Gen<object> ();
117
118         gs.newArr (3);
119         go.newArr (3);
120
121         return work ();
122     }
123 }