[rx] add missing project file generator helper files.
[mono-project.git] / mono / tests / dynamic-method-finalize.2.cs
blobbcc74ddb38144d3aa8107e1c2e853ab3d9bf0a99
1 using System;
2 using System.Reflection;
3 using System.Reflection.Emit;
5 delegate int Getter ();
7 class Host {
9 static int Field = 42;
11 Getter g;
13 public Host (Getter g) {
14 this.g = g;
17 ~Host () {
18 int d = g ();
19 Console.WriteLine (d);
23 class Program {
25 static Host h;
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));
40 /*
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
45 * work.
47 h = new Host (g);
49 return 0;