[2019-12] [threads] Add back mono_threads_attach_tools_thread as a public API (#18074)
[mono-project.git] / mono / tests / remoting3.cs
blob77fb860e655b2cb288f01a1f8ba746fdb1b1afe7
1 using System;
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())
13 this.target = target;
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++) {
22 if (i != 0)
23 Console.Write (", ");
24 Console.Write (call.GetArgName (i) + " " +
25 call.GetArg (i));
27 Console.WriteLine (")");
28 Console.Write ("INARGS(");
29 for (int i = 0; i < call.InArgCount; i++) {
30 if (i != 0)
31 Console.Write (", ");
32 Console.Write (call.GetInArgName (i) + " " +
33 call.GetInArg (i));
35 Console.WriteLine (")");
37 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
39 Console.Write ("RESARGS(");
40 for (int i = 0; i < res.ArgCount; i++) {
41 if (i != 0)
42 Console.Write (", ");
43 Console.Write (res.GetArgName (i) + " " +
44 res.GetArg (i));
46 Console.WriteLine (")");
48 Console.Write ("RESOUTARGS(");
49 for (int i = 0; i < res.OutArgCount; i++) {
50 if (i != 0)
51 Console.Write (", ");
52 Console.Write (res.GetOutArgName (i) + " " +
53 res.GetOutArg (i));
55 Console.WriteLine (")");
57 return res;
61 public struct MyStruct {
62 public int a;
63 public int b;
64 public int c;
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");
73 c = a + b;
75 MyStruct res = new MyStruct ();
77 res.a = a;
78 res.b = b;
79 res.c = c;
81 return res;
84 public long nonvirtual_Add (int a, int b) {
85 Console.WriteLine ("nonvirtual_Add");
86 return a + b;
90 class Test {
92 delegate MyStruct RemoteDelegate1 (int a, out int c, int b);
94 static int Main () {
95 R1 myobj = new R1 ();
96 int res = 0;
98 MyProxy real_proxy = new MyProxy (myobj);
100 R1 o = (R1)real_proxy.GetTransparentProxy ();
102 RemoteDelegate1 d1 = new RemoteDelegate1 (o.Add);
104 IAsyncResult ar = d1.BeginInvoke (2, out res, 3, null, null);
105 MyStruct myres = d1.EndInvoke (out res, ar);
107 Console.WriteLine ("Result: " + myres.a + " " +
108 myres.b + " " + myres.c + " " + res);
109 if (myres.a != 2)
110 return 1;
112 if (myres.b != 3)
113 return 2;
115 if (myres.c != 5)
116 return 3;
118 if (res != 5)
119 return 4;
121 return 0;