Align libgc vcxproj with makefile.
[mono.git] / mono / tests / remoting2.cs
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;
7
8 class MyProxy : RealProxy {
9         readonly MarshalByRefObject target;
10
11         public MyProxy (MarshalByRefObject target) : base (target.GetType())
12         {
13                 this.target = target;
14         }
15
16         public override IMessage Invoke (IMessage request) {
17                 IMethodCallMessage call = (IMethodCallMessage)request;
18                 Console.WriteLine ("Invoke " + call.MethodName);
19
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));
26                 }
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));
34                 }
35                 Console.WriteLine (")");
36
37                 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
38
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));
45                 }
46                 Console.WriteLine (")");                
47                 
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));
54                 }
55                 Console.WriteLine (")");                
56                 
57                 return res;
58         }
59 }
60
61 public struct MyStruct {
62         public int a;
63         public int b;
64         public int c;
65 }
66         
67 class R1 : MarshalByRefObject {
68
69         public int test_field = 5;
70         
71         public virtual MyStruct Add (int a, out int c, int b) {
72                 Console.WriteLine ("ADD");
73                 c = a + b;
74
75                 MyStruct res = new MyStruct ();
76
77                 res.a = a;
78                 res.b = b;
79                 res.c = c;
80                 
81                 return res;
82         }
83
84         public long nonvirtual_Add (int a, int b) {
85                 Console.WriteLine ("nonvirtual_Add");
86                 return a + b;
87         }
88 }
89
90 class Test {
91
92         delegate long RemoteDelegate2 (int a, int b);
93
94         
95         static int Main () {
96                 R1 myobj = new R1 ();
97                 long lres;
98                 
99                 MyProxy real_proxy = new MyProxy (myobj);
100
101                 R1 o = (R1)real_proxy.GetTransparentProxy ();
102
103                 RemoteDelegate2 d2 = new RemoteDelegate2 (o.nonvirtual_Add);
104                 d2 (6, 7);
105                 
106                 IAsyncResult ar1 = d2.BeginInvoke (2, 4, null, null);
107                 lres = d2.EndInvoke (ar1);
108                 if (lres != 6)
109                         return 1;
110
111                 return 0;
112         }
113 }