2 using System.Reflection;
5 public delegate object ArrDel (int i);
8 public object newArr (int 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);
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);
30 Console.WriteLine ("methods equal");
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");
45 if (sad.Method != miStr) {
46 Console.WriteLine ("wrong string method");
47 if (sad.Method == miObj)
48 Console.WriteLine ("string method is object");
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");
62 Console.WriteLine ("calling object del");
63 if (oad (go, 3).GetType () != typeof (object [])) {
64 Console.WriteLine ("not object array");
68 Console.WriteLine ("calling string del");
69 if (sad (gs, 3).GetType () != typeof (string [])) {
70 Console.WriteLine ("not string array");
74 Console.WriteLine ("calling string del2");
75 if (sad2 (gs, 3).GetType () != typeof (string [])) {
76 Console.WriteLine ("not string2 array");
81 StrArrDel sad3 = (StrArrDel)Delegate.CreateDelegate (typeof (StrArrDel), null, miObj);
82 Console.WriteLine ("object method for string delegate");
84 } catch (ArgumentException) {
88 DelObj delObj = (DelObj)Delegate.CreateDelegate (typeof (DelObj), null, miObj);
90 if (delObj (go, 3).GetType () != typeof (object []))
93 DelStr delStr = (DelStr)Delegate.CreateDelegate (typeof (DelStr), null, miStr);
95 if (delStr (gs, 3).GetType () != typeof (string []))
100 ArrDel ad = go.newDel ();
101 if (ad (3).GetType () != typeof (object []))
105 if (ad (3).GetType () != typeof (string []))
109 Console.WriteLine ("done");
114 public static int Main () {
115 Gen<string> gs = new Gen<string> ();
116 Gen<object> go = new Gen<object> ();