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 struct MyStruct {
67 class R1 : MarshalByRefObject {
69 public int test_field = 5;
71 public virtual MyStruct Add (int a, out int c, int b) {
72 Console.WriteLine ("ADD");
75 MyStruct res = new MyStruct ();
84 public long nonvirtual_Add (int a, int b) {
85 Console.WriteLine ("nonvirtual_Add");
92 delegate MyStruct RemoteDelegate1 (int a, out int c, int b);
93 delegate long RemoteDelegate2 (int a, int b);
95 static long test_call (R1 o)
97 return o.nonvirtual_Add (2, 3);
101 R1 myobj = new R1 ();
105 MyProxy real_proxy = new MyProxy (myobj);
107 R1 o = (R1)real_proxy.GetTransparentProxy ();
109 if (RemotingServices.IsTransparentProxy (null))
112 if (!RemotingServices.IsTransparentProxy (o))
115 if (o.GetType () != myobj.GetType ())
118 MyStruct myres = o.Add (2, out res, 3);
120 Console.WriteLine ("Result: " + myres.a + " " +
121 myres.b + " " + myres.c + " " + res);
137 lres = test_call (o2);
139 lres = test_call (o);
141 Console.WriteLine ("Result: " + lres);
145 lres = test_call (o);
149 Console.WriteLine ("test_field: " + o.test_field);
150 if (o.test_field != 2)
153 RemoteDelegate1 d1 = new RemoteDelegate1 (o.Add);
154 MyStruct myres2 = d1 (2, out res, 3);
156 Console.WriteLine ("Result: " + myres2.a + " " +
157 myres2.b + " " + myres2.c + " " + res);
171 RemoteDelegate2 d2 = new RemoteDelegate2 (o.nonvirtual_Add);