2 using System.Reflection;
3 using System.Reflection.Emit;
4 using System.Runtime.InteropServices;
5 using System.Runtime.CompilerServices;
6 using System.Threading;
8 delegate int Getter ();
12 static int Field = 42;
16 public Host (Getter g) {
21 Console.WriteLine ("got finalizated");
28 internal static Getter resed;
30 static void DoStuff ()
32 DynamicMethod method = new DynamicMethod ("GetField",
33 typeof (int), new Type [0], Type.GetType ("Host"));
35 ILGenerator il = method.GetILGenerator ();
36 il.Emit (OpCodes.Ldsfld, typeof (Host).GetField ("Field", BindingFlags.Static | BindingFlags.NonPublic));
37 il.Emit (OpCodes.Ret);
39 var g = (Getter)method.CreateDelegate (typeof (Getter));
43 static bool CheckStuff () {
46 Program.result = resed ();
51 public static int Main ()
54 var t = new Thread (DoStuff);
61 GC.WaitForPendingFinalizers ();
65 GC.WaitForPendingFinalizers ();
66 Console.WriteLine ("done with finalizers");
67 return result == 42 ? 0 : 1;