cleol
[mcs.git] / tests / test-19.cs
blobb04589cdc95029b14cde195c9e5d23fe8f32be4c
1 using System;
2 using System.Threading;
3 using System.Reflection;
5 class I {
7 public delegate string GetTextFn (string a);
9 static public GetTextFn GetText;
11 static string fn (string s)
13 return "(" + s + ")";
16 static I ()
18 GetText = new GetTextFn (fn);
22 class X {
24 public delegate int Foo (int i, int j);
26 private void Thread_func () {
27 Console.WriteLine ("Inside the thread !");
30 public int Func (int i, int j)
32 return i+j;
35 public void Bar ()
37 Foo my_func = new Foo (Func);
39 int result = my_func (2, 4);
41 Console.WriteLine ("Answer is : " + result);
44 static bool MyFilter (MemberInfo mi, object criteria)
46 Console.WriteLine ("You passed in : " + criteria);
47 return true;
50 public static int Main ()
52 I.GetTextFn _ = I.GetText;
54 Console.WriteLine ("Value: " + I.GetText);
55 X x = new X ();
57 Thread thr = new Thread (new ThreadStart (x.Thread_func));
59 thr.Start ();
60 Console.WriteLine ("Inside main ");
61 thr.Join ();
63 Console.WriteLine (_("Hello"));
65 x.Bar ();
67 MemberFilter filter = new MemberFilter (MyFilter);
69 Type t = x.GetType ();
71 MemberInfo [] mi = t.FindMembers (MemberTypes.Method, BindingFlags.Static | BindingFlags.NonPublic,
72 Type.FilterName, "MyFilter");
74 Console.WriteLine ("FindMembers called, mi = " + mi);
75 Console.WriteLine (" Count: " + mi.Length);
76 if (!filter (mi [0], "MyFilter"))
77 return 1;
80 // This test is used to call into a delegate defined in a separate
81 // namespace, but which is still not a nested delegate inside a class
83 NameSpace.TestDelegate td = new NameSpace.TestDelegate (multiply_by_three);
85 if (td (8) != 24)
86 return 30;
89 // Check the names that were used to define the delegates
91 if (td.GetType ().FullName != "NameSpace.TestDelegate")
92 return 31;
94 if (_.GetType ().FullName != "I+GetTextFn")
95 return 32;
97 Console.WriteLine ("Test passes");
99 return 0;
102 static int multiply_by_three (int v)
104 return v * 3;
109 namespace NameSpace {
111 public delegate int TestDelegate (int a);
116 namespace TestNamespace
118 public class TestClass
120 public delegate float NotWorkingDelegate(float point, params object [] hiddenParams);