2 using System.Reflection;
3 using System.Reflection.Emit;
5 delegate int Getter ();
13 public Host (Getter g) {
19 Console.WriteLine (d);
27 public static int Main ()
29 DynamicMethod method = new DynamicMethod ("GetField",
30 typeof (int), new Type [0], Type.GetType ("Host"));
32 ILGenerator il = method.GetILGenerator ();
33 il.Emit (OpCodes.Ldsfld, typeof (Host).GetField (
34 "Field", BindingFlags.Static |
35 BindingFlags.NonPublic));
36 il.Emit (OpCodes.Ret);
38 Getter g = (Getter) method.CreateDelegate (typeof (Getter));
41 * Create an object whose finalizer calls a dynamic method which
42 * dies at the same time.
43 * Storing into a static guarantees that this is only finalized during
44 * shutdown. This is needed since the !shutdown case still doesn't