Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-19.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b04589cdc95029b14cde195c9e5d23fe8f32be4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Threading;
using System.Reflection;

class I {

	public delegate string GetTextFn (string a);

	static public GetTextFn GetText;

	static string fn (string s)
	{
		return "(" + s + ")";
	}
	
	static I ()
	{
		GetText = new GetTextFn (fn);
	}
}

class X {

	public delegate int Foo (int i, int j);
	
	private void Thread_func () {
		Console.WriteLine ("Inside the thread !");
	}

	public int Func (int i, int j)
	{
		return i+j;
	}

	public void Bar ()
	{
		Foo my_func = new Foo (Func);

		int result = my_func (2, 4);

		Console.WriteLine ("Answer is : " + result);
	}

	static bool MyFilter (MemberInfo mi, object criteria)
	{
		Console.WriteLine ("You passed in : " + criteria);
		return true;
	}
	
	public static int Main ()
	{
		I.GetTextFn _ = I.GetText;

	Console.WriteLine ("Value: " + I.GetText);
		X x = new X ();

		Thread thr = new Thread (new ThreadStart (x.Thread_func));

		thr.Start ();
		Console.WriteLine ("Inside main ");
		thr.Join ();

		Console.WriteLine (_("Hello"));

		x.Bar ();

		MemberFilter filter = new MemberFilter (MyFilter);

		Type t = x.GetType ();

		MemberInfo [] mi = t.FindMembers (MemberTypes.Method, BindingFlags.Static | BindingFlags.NonPublic,
						  Type.FilterName, "MyFilter");

		Console.WriteLine ("FindMembers called, mi = " + mi);
		Console.WriteLine ("   Count: " + mi.Length);
		if (!filter (mi [0], "MyFilter"))
			return 1;

		//
		// This test is used to call into a delegate defined in a separate
		// namespace, but which is still not a nested delegate inside a class
		//
		NameSpace.TestDelegate td = new NameSpace.TestDelegate (multiply_by_three);

		if (td (8) != 24)
			return 30;

		//
		// Check the names that were used to define the delegates
		//
		if (td.GetType ().FullName != "NameSpace.TestDelegate")
			return 31;

		if (_.GetType ().FullName != "I+GetTextFn")
			return 32;
		
		Console.WriteLine ("Test passes");

		return 0;
	}

	static int multiply_by_three (int v)
	{
		return v * 3;
	}
	
}

namespace NameSpace {

	public delegate int TestDelegate (int a);

}


namespace TestNamespace
{
	public class TestClass
	{
		public delegate float NotWorkingDelegate(float point, params object [] hiddenParams);
	}
}