File: ReflectionCalls.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (177 lines) | stat: -rw-r--r-- 6,514 bytes parent folder | download | duplicates (13)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//
// MonoTests.Remoting.ReflectionCalls.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//

using System;
using System.Reflection;
using System.Collections;
using NUnit.Framework;
using System.Text;
using System.Runtime.InteropServices;

namespace MonoTests.Remoting
{
	public abstract class ReflectionCallTest : BaseCallTest
	{
		public override InstanceSurrogate GetInstanceSurrogate () { return new ReflectionInstanceSurrogate (); }
		public override AbstractSurrogate GetAbstractSurrogate () { return new ReflectionAbstractSurrogate (); }
		public override InterfaceSurrogate GetInterfaceSurrogate () { return new ReflectionInterfaceSurrogate (); }

		public static int Simple (Type type, object target)
		{
			object[] parms = new object[0];
			MethodBase m = type.GetMethod ("Simple");
			return (int) m.Invoke (target, parms);
		}

		public static string PrimitiveParams (Type type, object target, int a, uint b, char c, string d)
		{
			object[] parms = new object[] {a,b,c,d};
			Type[] sig = new Type[] {typeof (int), typeof (uint), typeof (char), typeof (string)};
			MethodBase m = type.GetMethod ("PrimitiveParams", sig);
			return (string) m.Invoke (target, parms);
		}

		public static string PrimitiveParamsInOut (Type type, object target, ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			object[] parms = new object[] {a1,0,b1,0f,filler,c1,'\0',d1,null};
			MethodBase m = type.GetMethod ("PrimitiveParamsInOut");
			string res = (string) m.Invoke (target, parms);
			a1 = (int)parms[0];
			b1 = (float)parms[2];
			c1 = (char)parms[5];
			d1 = (string)parms[7];
			a2 = (int)parms[1];
			b2 = (float)parms[3];
			c2 = (char)parms[6];
			d2 = (string)parms[8];
			return res;
		}

		public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
		{
			object[] parms = new object[] {a,b,c};
			MethodBase m = type.GetMethod ("ComplexParams");
			return (Complex) m.Invoke (target, parms);
		}

		public static Complex ComplexParamsInOut (Type type, object target, ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
		{
			object[] parms = new object[] {a,null,bytes,sb,c};
			MethodBase m = type.GetMethod ("ComplexParamsInOut");
			Complex res = (Complex) m.Invoke (target, parms);
			a = (ArrayList) parms[0];
			b = (Complex) parms[1];
			return res;
		}

		public static void ProcessContextData (Type type, object target)
		{
			MethodBase m = type.GetMethod ("ProcessContextData");
			m.Invoke (target, null);
		}
	}

	public class ReflectionInstanceSurrogate : InstanceSurrogate
	{
		public override int Simple ()
		{
			return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
		}

		public override string PrimitiveParams (int a, uint b, char c, string d)
		{
			return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
		}

		public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
		}

		public override Complex ComplexParams (ArrayList a, Complex b, string c)
		{
			return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
		}

		public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
		{
			return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
		}

		public override void ProcessContextData ()
		{
			ReflectionCallTest.ProcessContextData (typeof (RemoteObject), RemoteObject);
		}
	}

	public class ReflectionAbstractSurrogate : AbstractSurrogate
	{
		public override int Simple ()
		{
			return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
		}

		public override string PrimitiveParams (int a, uint b, char c, string d)
		{
			return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
		}

		public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
		}

		public override Complex ComplexParams (ArrayList a, Complex b, string c)
		{
			return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
		}

		public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
		{
			return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
		}

		public override void ProcessContextData ()
		{
			ReflectionCallTest.ProcessContextData (typeof (AbstractRemoteObject), RemoteObject);
		}
	}

	public class ReflectionInterfaceSurrogate : InterfaceSurrogate
	{
		public override int Simple ()
		{
			return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
		}

		public override string PrimitiveParams (int a, uint b, char c, string d)
		{
			return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
		}

		public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
		{
			return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
		}

		public override Complex ComplexParams (ArrayList a, Complex b, string c)
		{
			return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
		}

		public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
		{
			return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
		}

		public override void ProcessContextData ()
		{
			ReflectionCallTest.ProcessContextData (typeof (IRemoteObject), RemoteObject);
		}
	}
}