2 using System
.Threading
;
3 using System
.Reflection
;
7 public delegate string GetTextFn (string a
);
9 static public GetTextFn GetText
;
11 static string fn (string s
)
18 GetText
= new GetTextFn (fn
);
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
)
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
);
50 public static int Main ()
52 I
.GetTextFn _
= I
.GetText
;
54 Console
.WriteLine ("Value: " + I
.GetText
);
57 Thread thr
= new Thread (new ThreadStart (x
.Thread_func
));
60 Console
.WriteLine ("Inside main ");
63 Console
.WriteLine (_("Hello"));
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"))
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
);
89 // Check the names that were used to define the delegates
91 if (td
.GetType ().FullName
!= "NameSpace.TestDelegate")
94 if (_
.GetType ().FullName
!= "I+GetTextFn")
97 Console
.WriteLine ("Test passes");
102 static int multiply_by_three (int v
)
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
);