5f331d72715b5603716c95fdceaf032c6bdce060
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / MethodReturnMessageWrapper.cs
1 //
2 // System.Runtime.Remoting.Messaging.MethodReturnMessageWrapper.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 //         Lluis Sanchez Gual (lluis@ideary.com)
6 //
7 // 2002 (C) Copyright, Ximian, Inc.
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Collections;
35 using System.Reflection;
36 using System.Runtime.Serialization;
37
38 namespace System.Runtime.Remoting.Messaging {
39
40         public class MethodReturnMessageWrapper : InternalMessageWrapper, IMethodReturnMessage, IMethodMessage, IMessage
41         {
42                 object[] _args;
43                 ArgInfo _outArgInfo;
44                 DictionaryWrapper _properties;
45                 Exception _exception;
46                 object _return;
47
48                 public MethodReturnMessageWrapper (IMethodReturnMessage msg)
49                         : base (msg)
50                 {
51                         _args = ((IMethodCallMessage)WrappedMessage).Args;
52                         _exception = msg.Exception;
53                         _outArgInfo = new ArgInfo (msg.MethodBase, ArgInfoType.Out);
54                 }
55
56                 public virtual int ArgCount {
57                         get { return ((IMethodReturnMessage)WrappedMessage).ArgCount; }
58                 }
59
60                 public virtual object [] Args \r
61                 {
62                         get { return _args; }
63                         set { _args = value; }
64                 }
65
66                 public virtual Exception Exception {
67                         get { return _exception; }
68                         set { _exception = value; }
69                 }
70                 
71                 public virtual bool HasVarArgs {
72                         get { return ((IMethodReturnMessage)WrappedMessage).HasVarArgs; }
73                 }
74                 
75                 public virtual LogicalCallContext LogicalCallContext {
76                         get { return ((IMethodReturnMessage)WrappedMessage).LogicalCallContext; }
77                 }
78                 
79                 public virtual MethodBase MethodBase {
80                         get { return ((IMethodReturnMessage)WrappedMessage).MethodBase; }
81                 }
82
83                 public virtual string MethodName {
84                         get { return ((IMethodReturnMessage)WrappedMessage).MethodName; }
85                 }
86
87                 public virtual object MethodSignature {
88                         get { return ((IMethodReturnMessage)WrappedMessage).MethodSignature; }
89                 }
90
91                 public virtual int OutArgCount {
92                         get { return _outArgInfo.GetInOutArgCount(); }
93                 }
94
95                 public virtual object[] OutArgs {
96                         get { return _outArgInfo.GetInOutArgs (_args); }
97                 }
98
99                 public virtual IDictionary Properties 
100                 {
101                         get { 
102                                 if (_properties == null) _properties = new DictionaryWrapper(this, WrappedMessage.Properties);
103                                 return _properties; 
104                         }
105                 }
106
107                 public virtual object ReturnValue {
108                         get { return _return; }
109                         set { _return = value; }
110                 }
111
112                 public virtual string TypeName {
113                         get { return ((IMethodReturnMessage)WrappedMessage).TypeName; }
114                 }
115
116                 public virtual string Uri \r
117                 {
118                         get { return ((IMethodReturnMessage)WrappedMessage).Uri; }
119                         set { Properties["__Uri"] = value; }
120                 }
121
122                 public virtual object GetArg (int argNum)
123                 {
124                         return _args[argNum];
125                 }
126
127                 public virtual string GetArgName (int index)
128                 {
129                         return ((IMethodReturnMessage)WrappedMessage).GetArgName(index);
130                 }
131
132                 public virtual object GetOutArg (int argNum)
133                 {
134                         return _args [_outArgInfo.GetInOutArgIndex (argNum)];
135                 }
136
137                 public virtual string GetOutArgName (int index)
138                 {
139                         return _outArgInfo.GetInOutArgName(index);
140                 }
141
142                 class DictionaryWrapper : MethodReturnDictionary\r
143                 {\r
144                         IDictionary _wrappedDictionary;\r
145                         static string[] _keys = new string[] {"__Args", "__Return"};\r
146 \r
147                         public DictionaryWrapper(IMethodReturnMessage message, IDictionary wrappedDictionary) : base (message)\r
148                         {\r
149                                 _wrappedDictionary = wrappedDictionary;\r
150                                 MethodKeys = _keys;\r
151                         }\r
152
153                         protected override IDictionary AllocInternalProperties()\r
154                         {\r
155                                 return _wrappedDictionary;\r
156                         }\r
157
158                         protected override void SetMethodProperty (string key, object value)
159                         {
160                                 if (key == "__Args") ((MethodReturnMessageWrapper)_message)._args = (object[])value;
161                                 else if (key == "__Return") ((MethodReturnMessageWrapper)_message)._return = value;
162                                 else base.SetMethodProperty (key, value);
163                         }
164
165                         protected override object GetMethodProperty (string key)
166                         {
167                                 if (key == "__Args") return ((MethodReturnMessageWrapper)_message)._args;
168                                 else if (key == "__Return") return ((MethodReturnMessageWrapper)_message)._return;
169                                 else return base.GetMethodProperty (key);
170                         }
171                 }
172         }
173 }