2 using System.Threading;
3 using System.Runtime.InteropServices;
4 using System.Runtime.Remoting;
5 using System.Runtime.Remoting.Messaging;
6 using System.Runtime.Remoting.Proxies;
8 class MyProxy : RealProxy {
9 readonly MarshalByRefObject target;
11 public MyProxy (MarshalByRefObject target) : base (target.GetType())
16 public override IMessage Invoke (IMessage request) {
17 IMethodCallMessage call = (IMethodCallMessage)request;
18 Console.WriteLine ("Invoke " + call.MethodName);
20 Console.Write ("ARGS(");
21 for (int i = 0; i < call.ArgCount; i++) {
24 Console.Write (call.GetArgName (i) + " " +
27 Console.WriteLine (")");
28 Console.Write ("INARGS(");
29 for (int i = 0; i < call.InArgCount; i++) {
32 Console.Write (call.GetInArgName (i) + " " +
35 Console.WriteLine (")");
37 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
39 Console.Write ("RESARGS(");
40 for (int i = 0; i < res.ArgCount; i++) {
43 Console.Write (res.GetArgName (i) + " " +
46 Console.WriteLine (")");
48 Console.Write ("RESOUTARGS(");
49 for (int i = 0; i < res.OutArgCount; i++) {
52 Console.Write (res.GetOutArgName (i) + " " +
55 Console.WriteLine (")");
61 public class EmptyProxy : RealProxy
63 public EmptyProxy ( Type type ) : base( type )
67 public override IMessage Invoke( IMessage msg )
69 IMethodCallMessage call = (IMethodCallMessage)msg;
71 return new ReturnMessage( null, null, 0, null, call );
75 public struct MyStruct {
84 class R1 : MarshalByRefObject, R2 {
86 public int test_field = 5;
87 public object null_test_field;
89 public virtual MyStruct Add (int a, out int c, int b) {
90 Console.WriteLine ("ADD");
93 MyStruct res = new MyStruct ();
102 public long nonvirtual_Add (int a, int b) {
103 Console.WriteLine ("nonvirtual_Add " + a + " + " + b);
108 class R3 : MarshalByRefObject {
109 public object anObject;
114 delegate MyStruct RemoteDelegate1 (int a, out int c, int b);
115 delegate long RemoteDelegate2 (int a, int b);
117 static long test_call (R1 o)
119 return o.nonvirtual_Add (2, 3);
123 R1 myobj = new R1 ();
127 MyProxy real_proxy = new MyProxy (myobj);
129 R1 o = (R1)real_proxy.GetTransparentProxy ();
131 if (RemotingServices.IsTransparentProxy (null))
134 if (!RemotingServices.IsTransparentProxy (o))
137 Console.WriteLine ("XXXXXXXXXXXX: " + RemotingServices.GetRealProxy (o));
139 if (o.GetType () != myobj.GetType ())
142 MyStruct myres = o.Add (2, out res, 3);
144 Console.WriteLine ("Result: " + myres.a + " " +
145 myres.b + " " + myres.c + " " + res);
161 lres = test_call (o2);
163 lres = test_call (o);
165 Console.WriteLine ("Result: " + lres);
169 lres = test_call (o);
173 Console.WriteLine ("test_field: " + o.test_field);
174 if (o.test_field != 2)
177 RemoteDelegate1 d1 = new RemoteDelegate1 (o.Add);
178 MyStruct myres2 = d1 (2, out res, 3);
180 Console.WriteLine ("Result: " + myres2.a + " " +
181 myres2.b + " " + myres2.c + " " + res);
195 RemoteDelegate2 d2 = new RemoteDelegate2 (o.nonvirtual_Add);
198 if (!(real_proxy.GetTransparentProxy () is R2))
201 /* Test what happens if the proxy doesn't return the required information */
202 EmptyProxy handler = new EmptyProxy ( typeof (R3) );
203 R3 o3 = (R3)handler.GetTransparentProxy();
205 if (o3.anObject != null)
208 if (o.null_test_field != null)