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);
27 delegate string StringDelegate ();
32 Console.WriteLine ("Test.F from delegate");
34 public static string G (int a) {
36 throw new Exception ("Something went wrong in G");
37 return "G got: " + a.ToString ();
39 public string H (int a) {
41 throw new Exception ("Something went wrong in H");
42 return "H got: " + a.ToString () + " and " + data.ToString ();
45 public virtual void VF () {
46 Console.WriteLine ("Test.VF from delegate");
53 // Check that creation of delegates do not runs the class cctor
54 DoIt doit = new DoIt (B.method);
58 Test test = new Test ();
59 SimpleDelegate d = new SimpleDelegate (F);
60 SimpleDelegate d1 = new SimpleDelegate (test.VF);
61 NotSimpleDelegate d2 = new NotSimpleDelegate (G);
62 NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
65 // we run G() and H() before and after using them as delegates
66 // to be sure we don't corrupt them.
69 Console.WriteLine (d2 (2));
70 Console.WriteLine (d3 (3));
74 if (d.Method.Name != "F")
77 if (d3.Method == null)
81 Console.WriteLine (d3.DynamicInvoke (args));
83 AnotherDelegate d4 = new AnotherDelegate (puts);
84 if (d4.Method == null)
87 Console.WriteLine (d4.Method);
88 Console.WriteLine (d4.Method.Name);
89 Console.WriteLine (d4.Method.DeclaringType);
91 // Check unboxing of this argument
93 StringDelegate d5 = new StringDelegate (x.ToString);