Thu Dec 19 00:06:57 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / MonoMethodMessage.cs
1 //
2 // System.Runtime.Remoting.Messaging.MonoMethodMessage.cs
3 //
4 // Author:
5 //   Dietmar Maurer (dietmar@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System;
11 using System.Collections;
12 using System.Reflection;
13 using System.Runtime.CompilerServices;
14
15 namespace System.Runtime.Remoting.Messaging {
16         
17         public class MonoMethodMessage : IMethodCallMessage, IMethodReturnMessage {
18
19                 MonoMethod method;
20
21                 object []  args;
22
23                 string []  names;
24
25                 byte [] arg_types; /* 1 == IN; 2 == OUT ; 3 = INOUT */
26
27                 public LogicalCallContext ctx;
28
29                 public object rval;
30
31                 public Exception exc;
32
33                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
34                 internal extern void InitMessage (MonoMethod method, object [] out_args);
35
36                 public MonoMethodMessage (MethodBase method, object [] out_args)
37                 {
38                         InitMessage ((MonoMethod)method, out_args);                     
39                 }
40
41                 public MonoMethodMessage (Type type, string method_name, object [] in_args)
42                 {
43                         // fixme: consider arg types
44                         MethodInfo minfo = type.GetMethod (method_name);
45                         
46                         InitMessage ((MonoMethod)minfo, null);
47
48                         int len = in_args.Length;
49                         for (int i = 0; i < len; i++) {
50                                 args [i] = in_args [i];
51                         }
52                 }
53                 
54                 public IDictionary Properties {
55                         get {
56                                 return null;
57                         }
58                 }
59
60                 public int ArgCount {
61                         get {
62                                 return args.Length;
63                         }
64                 }
65                 
66                 public object [] Args {
67                         get {
68                                 return args;
69                         }
70                 }
71                 
72                 public bool HasVarArgs {
73                         get {
74                                 return false;
75                         }
76                 }
77
78                 public LogicalCallContext LogicalCallContext {
79                         get {
80                                 return ctx;
81                         }
82                 }
83
84                 public MethodBase MethodBase {
85                         get {
86                                 return method;
87                         }
88                 }
89
90                 public string MethodName {
91                         get {
92                                 return method.Name;
93                         }
94                 }
95
96                 public object MethodSignature {
97                         get {
98                                 return null;
99                         }
100                 }
101
102                 public string TypeName {
103                         get {
104                                 return null;
105                         }
106                 }
107
108                 public string Uri {
109                         get {
110                                 return null;
111                         }
112
113                         set {
114                         }
115                 }
116
117                 public object GetArg (int arg_num)
118                 {
119                         return args [arg_num];
120                 }
121                 
122                 public string GetArgName (int arg_num)
123                 {
124                         return names [arg_num];
125                 }
126
127                 public int InArgCount {
128                         get {
129                                 int count = 0;
130
131                                 foreach (byte t in arg_types) {
132                                         if ((t & 1) != 0) count++;
133                                                 
134                                 }
135                                 return count;
136                         }
137                 }
138                 
139                 public object [] InArgs {
140                         get {
141                                 int i, j, count = InArgCount;
142                                 object [] inargs = new object [count];
143
144                                 i = j = 0;
145                                 foreach (byte t in arg_types) {
146                                         if ((t & 1) != 0)
147                                                 inargs [j++] = args [i];
148                                         i++;
149                                 }
150                                 
151                                 return inargs;
152                         }
153                 }
154                 
155                 public object GetInArg (int arg_num)
156                 {
157                         int i = 0, j = 0;
158                         foreach (byte t in arg_types) {
159                                 if ((t & 1) != 0) {
160                                         if (j++ == arg_num)
161                                                 return args [i]; 
162                                 }
163                                 i++;
164                         }
165                         return null;
166                 }
167                 
168                 public string GetInArgName (int arg_num)
169                 {
170                         int i = 0, j = 0;
171                         foreach (byte t in arg_types) {
172                                 if ((t & 1) != 0) {
173                                         if (j++ == arg_num)
174                                                 return names [i]; 
175                                 }
176                                 i++;
177                         }
178                         return null;
179                 }
180
181                 public Exception Exception {
182                         get {
183                                 return exc;
184                         }
185                 }
186                 
187                 public int OutArgCount {
188                         get {
189                                 int count = 0;
190
191                                 foreach (byte t in arg_types) {
192                                         if ((t & 2) != 0) count++;
193                                                 
194                                 }
195                                 return count;
196                         }
197                 }
198                 
199                 public object [] OutArgs {
200                         get {
201                                 int i, j, count = OutArgCount;
202                                 object [] outargs = new object [count];
203
204                                 i = j = 0;
205                                 foreach (byte t in arg_types) {
206                                         if ((t & 2) != 0)
207                                                 outargs [j++] = args [i];
208                                         i++;
209                                 }
210                                 
211                                 return outargs;
212                         }
213                 }
214                 
215                 public object ReturnValue {
216                         get {
217                                 return rval;
218                         }
219                 }
220
221                 public object GetOutArg (int arg_num)
222                 {
223                         int i = 0, j = 0;
224                         foreach (byte t in arg_types) {
225                                 if ((t & 2) != 0) {
226                                         if (j++ == arg_num)
227                                                 return args [i]; 
228                                 }
229                                 i++;
230                         }
231                         return null;
232                 }
233                 
234                 public string GetOutArgName (int arg_num)
235                 {
236                         int i = 0, j = 0;
237                         foreach (byte t in arg_types) {
238                                 if ((t & 2) != 0) {
239                                         if (j++ == arg_num)
240                                                 return names [i]; 
241                                 }
242                                 i++;
243                         }
244                         return null;
245                 }
246
247         }
248 }