2 using System.Reflection;
3 using System.Reflection.Emit;
4 using System.Runtime.InteropServices;
5 using System.Runtime.CompilerServices;
7 delegate int Getter ();
11 static int Field = 42;
15 public Host (Getter g) {
26 internal static Getter resed;
28 static void DoStuff ()
30 DynamicMethod method = new DynamicMethod ("GetField",
31 typeof (int), new Type [0], Type.GetType ("Host"));
33 ILGenerator il = method.GetILGenerator ();
34 il.Emit (OpCodes.Ldsfld, typeof (Host).GetField ("Field", BindingFlags.Static | BindingFlags.NonPublic));
35 il.Emit (OpCodes.Ret);
37 var g = (Getter)method.CreateDelegate (typeof (Getter));
41 static bool CheckStuff () {
44 Program.result = resed ();
49 public static int Main ()
57 GC.WaitForPendingFinalizers ();
60 GC.WaitForPendingFinalizers ();
61 return result == 42 ? 0 : 1;