2 using System
.Reflection
;
3 using System
.Reflection
.Emit
;
12 delegate int Getter ();
14 public static int Main ()
16 DynamicMethod method
= new DynamicMethod ("GetField",
17 typeof (int), new Type
[0], Type
.GetType ("Host"));
19 ILGenerator il
= method
.GetILGenerator ();
20 il
.Emit (OpCodes
.Ldsfld
, typeof (Host
).GetField (
21 "Field", BindingFlags
.Static
|
22 BindingFlags
.NonPublic
));
23 il
.Emit (OpCodes
.Ret
);
25 Getter g
= (Getter
) method
.CreateDelegate (typeof (Getter
));
27 Console
.WriteLine (g ());