2 using System
.Reflection
;
3 using System
.Globalization
;
4 using System
.Diagnostics
;
13 public static int test2 (ref EmptyStruct foo
) {
14 return foo
.value + 20;
18 delegate int ActionRef (ref EmptyStruct _this
);
19 delegate int ActionRef2 ();
20 delegate int ActionRef3 (EmptyStruct _this
);
29 delegate Foo
NoArgDele ();
30 delegate Foo
OneArgDele (Driver d
);
35 public static Foo
M0 () { return new Foo (10); }
36 public Foo
M1 () { return new Foo (this == null ? 10 : 20); }
37 public static Foo
M2 (string x
) { return new Foo (30); }
38 public static Foo
M2i (int x
) { return new Foo (40); }
39 public static Foo
M3 (object x
) { return new Foo (50); }
40 public virtual Foo
M4 () { return new Foo (this == null ? 60 : 70); }
42 public static int Main () {
43 int r
= test_0_refobj_invokes ();
46 r
= test_0_valuetype_invokes ();
52 public static int test_0_refobj_invokes ()
65 x
= (NoArgDele
)Delegate
.CreateDelegate (typeof (NoArgDele
), "10", typeof (Driver
).GetMethod ("M2"));
69 x
= (NoArgDele
)Delegate
.CreateDelegate (typeof (NoArgDele
), null, typeof (Driver
).GetMethod ("M3"));
73 y
= (OneArgDele
)Delegate
.CreateDelegate (typeof (OneArgDele
), null, typeof (Driver
).GetMethod ("M4"));
74 if (y (new Driver ()).x
!= 70)
77 x
= (NoArgDele
)Delegate
.CreateDelegate (typeof (NoArgDele
), null, typeof (Driver
).GetMethod ("M1"));
81 x
= (NoArgDele
)Delegate
.CreateDelegate (typeof (NoArgDele
), null, typeof (Driver
).GetMethod ("M4"));
88 public static int test_0_valuetype_invokes ()
90 EmptyStruct es
= default (EmptyStruct
);
93 var ar1
= (ActionRef
)Delegate
.CreateDelegate(typeof (ActionRef
), typeof (EmptyStruct
).GetMethod("test"));
94 if (ar1 (ref es
) != 110) {
95 Console
.WriteLine ("expected 110, got {0}", ar1 (ref es
));
99 var ar2
= (ActionRef2
)Delegate
.CreateDelegate (typeof (ActionRef2
), null, typeof (EmptyStruct
).GetMethod("test"));
101 Console
.WriteLine ("must not return, got {0}", ar2 ());
103 } catch (NullReferenceException
) {
106 ar1
= (ActionRef
) Delegate
.CreateDelegate(typeof (ActionRef
), typeof (EmptyStruct
).GetMethod("test2"));
107 if (ar1 (ref es
) != 120) {
108 Console
.WriteLine ("expected 120, got {0}", ar1 (ref es
));
112 ar2
= (ActionRef2
) Delegate
.CreateDelegate(typeof (ActionRef2
), es
, typeof (EmptyStruct
).GetMethod("test"));
114 Console
.WriteLine ("expected 110 got {0}", ar2 ());
119 Delegate
.CreateDelegate(typeof (ActionRef2
), new EmptyStruct (), typeof (EmptyStruct
).GetMethod("test2"));
120 Console
.WriteLine ("must fail/2");
122 } catch (ArgumentException
) {}
125 Delegate
.CreateDelegate(typeof (ActionRef3
), typeof (EmptyStruct
).GetMethod("test"));
126 Console
.WriteLine ("must fail/2");
128 } catch (ArgumentException
) {}