2 // System.Runtime.Remoting.Messaging.MethodReturnMessageWrapper.cs
4 // Author: Duncan Mak (duncan@ximian.com)
5 // Lluis Sanchez Gual (lluis@ideary.com)
7 // 2002 (C) Copyright, Ximian, Inc.
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
34 using System.Collections;
35 using System.Reflection;
36 using System.Runtime.Serialization;
38 namespace System.Runtime.Remoting.Messaging {
40 public class MethodReturnMessageWrapper : InternalMessageWrapper, IMethodReturnMessage, IMethodMessage, IMessage
44 DictionaryWrapper _properties;
48 public MethodReturnMessageWrapper (IMethodReturnMessage msg)
51 if (msg.Exception != null) {
52 _exception = msg.Exception;
53 _args = new object[0];
56 _return = msg.ReturnValue;
57 if (msg.MethodBase != null)
58 _outArgInfo = new ArgInfo (msg.MethodBase, ArgInfoType.Out);
62 public virtual int ArgCount {
63 get { return _args.Length; }
66 public virtual object [] Args
\r
69 set { _args = value; }
72 public virtual Exception Exception {
73 get { return _exception; }
74 set { _exception = value; }
77 public virtual bool HasVarArgs {
78 get { return ((IMethodReturnMessage)WrappedMessage).HasVarArgs; }
81 public virtual LogicalCallContext LogicalCallContext {
82 get { return ((IMethodReturnMessage)WrappedMessage).LogicalCallContext; }
85 public virtual MethodBase MethodBase {
86 get { return ((IMethodReturnMessage)WrappedMessage).MethodBase; }
89 public virtual string MethodName {
90 get { return ((IMethodReturnMessage)WrappedMessage).MethodName; }
93 public virtual object MethodSignature {
94 get { return ((IMethodReturnMessage)WrappedMessage).MethodSignature; }
97 public virtual int OutArgCount {
98 get { return _outArgInfo != null ? _outArgInfo.GetInOutArgCount() : 0; }
101 public virtual object[] OutArgs {
102 get { return _outArgInfo != null ? _outArgInfo.GetInOutArgs (_args) : _args; }
105 public virtual IDictionary Properties
108 if (_properties == null) _properties = new DictionaryWrapper(this, WrappedMessage.Properties);
113 public virtual object ReturnValue {
114 get { return _return; }
115 set { _return = value; }
118 public virtual string TypeName {
119 get { return ((IMethodReturnMessage)WrappedMessage).TypeName; }
122 public virtual string Uri
\r
124 get { return ((IMethodReturnMessage)WrappedMessage).Uri; }
125 set { Properties["__Uri"] = value; }
128 public virtual object GetArg (int argNum)
130 return _args[argNum];
133 public virtual string GetArgName (int index)
135 return ((IMethodReturnMessage)WrappedMessage).GetArgName(index);
138 public virtual object GetOutArg (int argNum)
140 return _args [_outArgInfo.GetInOutArgIndex (argNum)];
143 public virtual string GetOutArgName (int index)
145 return _outArgInfo.GetInOutArgName(index);
148 class DictionaryWrapper : MethodReturnDictionary
\r
150 IDictionary _wrappedDictionary;
\r
151 static string[] _keys = new string[] {"__Args", "__Return"};
\r
153 public DictionaryWrapper(IMethodReturnMessage message, IDictionary wrappedDictionary) : base (message)
\r
155 _wrappedDictionary = wrappedDictionary;
\r
156 MethodKeys = _keys;
\r
159 protected override IDictionary AllocInternalProperties()
\r
161 return _wrappedDictionary;
\r
164 protected override void SetMethodProperty (string key, object value)
166 if (key == "__Args") ((MethodReturnMessageWrapper)_message)._args = (object[])value;
167 else if (key == "__Return") ((MethodReturnMessageWrapper)_message)._return = value;
168 else base.SetMethodProperty (key, value);
171 protected override object GetMethodProperty (string key)
173 if (key == "__Args") return ((MethodReturnMessageWrapper)_message)._args;
174 else if (key == "__Return") return ((MethodReturnMessageWrapper)_message)._return;
175 else return base.GetMethodProperty (key);