2002-02-20 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / tests / test-19.cs
1 using System;
2 using System.Threading;
3 using System.Reflection;
4
5 class I {
6
7         public delegate string GetTextFn (string a);
8
9         static public GetTextFn GetText;
10
11         static string fn (string s)
12         {
13                 return "(" + s + ")";
14         }
15         
16         static I ()
17         {
18                 GetText = new GetTextFn (fn);
19         }
20 }
21
22 class X {
23
24         public delegate int Foo (int i, int j);
25         
26         private void Thread_func () {
27                 Console.WriteLine ("Inside the thread !");
28         }
29
30         public int Func (int i, int j)
31         {
32                 return i+j;
33         }
34
35         public void Bar ()
36         {
37                 Foo my_func = new Foo (Func);
38
39                 int result = my_func (2, 4);
40
41                 Console.WriteLine ("Answer is : " + result);
42         }
43
44         static bool MyFilter (MemberInfo mi, object criteria)
45         {
46                 Console.WriteLine ("You passed in : " + criteria);
47                 return true;
48         }
49         
50         public static int Main ()
51         {
52                 I.GetTextFn _ = I.GetText;
53
54         Console.WriteLine ("Value: " + I.GetText);
55                 X x = new X ();
56
57                 Thread thr = new Thread (new ThreadStart (x.Thread_func));
58
59                 thr.Start ();
60                 Console.WriteLine ("Inside main ");
61                 thr.Join ();
62
63                 Console.WriteLine (_("Hello"));
64
65                 x.Bar ();
66
67                 MemberFilter filter = new MemberFilter (MyFilter);
68
69                 Type t = x.GetType ();
70
71                 MemberInfo [] mi = t.FindMembers (MemberTypes.Method, BindingFlags.Static | BindingFlags.NonPublic,
72                                                   Type.FilterName, "MyFilter");
73
74                 Console.WriteLine ("FindMembers called, mi = " + mi);
75                 Console.WriteLine ("   Count: " + mi.Length);
76                 if (!filter (mi [0], "MyFilter"))
77                         return 1;
78                 
79                 Console.WriteLine ("Test passes");
80
81                 return 0;
82         }
83 }