2 using System.Runtime.InteropServices;
5 public static bool b_cctor_run = false;
12 public static void method () {
16 delegate void DoIt ();
20 [DllImport("cygwin1.dll", EntryPoint="puts", CharSet=CharSet.Ansi)]
21 public static extern int puts (string name);
23 delegate void SimpleDelegate ();
24 delegate string NotSimpleDelegate (int a);
25 delegate int AnotherDelegate (string s);
30 Console.WriteLine ("Test.F from delegate");
32 public static string G (int a) {
34 throw new Exception ("Something went wrong in G");
35 return "G got: " + a.ToString ();
37 public string H (int a) {
39 throw new Exception ("Something went wrong in H");
40 return "H got: " + a.ToString () + " and " + data.ToString ();
43 public virtual void VF () {
44 Console.WriteLine ("Test.VF from delegate");
51 // Check that creation of delegates do not runs the class cctor
52 DoIt doit = new DoIt (B.method);
56 Test test = new Test ();
57 SimpleDelegate d = new SimpleDelegate (F);
58 SimpleDelegate d1 = new SimpleDelegate (test.VF);
59 NotSimpleDelegate d2 = new NotSimpleDelegate (G);
60 NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
63 // we run G() and H() before and after using them as delegates
64 // to be sure we don't corrupt them.
67 Console.WriteLine (d2 (2));
68 Console.WriteLine (d3 (3));
72 if (d.Method.Name != "F")
75 if (d3.Method == null)
79 Console.WriteLine (d3.DynamicInvoke (args));
81 AnotherDelegate d4 = new AnotherDelegate (puts);
82 if (d4.Method == null)
85 Console.WriteLine (d4.Method);
86 Console.WriteLine (d4.Method.Name);
87 Console.WriteLine (d4.Method.DeclaringType);