2 // System.Runtime.Remoting.Messaging.ReturnMessage.cs
5 // Dietmar Maurer (dietmar@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
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;
38 namespace System.Runtime.Remoting.Messaging
40 public class ReturnMessage : IMethodReturnMessage, IMethodMessage, IMessage, IInternalMessage
45 LogicalCallContext _callCtx;
49 MethodBase _methodBase;
51 Type [] _methodSignature;
53 MethodReturnDictionary _properties;
54 Identity _targetIdentity;
57 public ReturnMessage (object returnValue, object [] outArgs,
58 int outArgCount, LogicalCallContext callCtx,
59 IMethodCallMessage request)
61 // outArgCount tells how many values of outArgs are valid
63 _returnValue = returnValue;
65 _outArgsCount = outArgCount;
67 if (request != null) {
69 _methodBase = request.MethodBase;
71 if (_args == null) _args = new object [outArgCount];
74 public ReturnMessage (Exception exc, IMethodCallMessage request)
79 _methodBase = request.MethodBase;
80 _args = new object[0]; // .NET does this
89 public object [] Args {
95 public bool HasVarArgs {
97 if (_methodBase == null) return false;
98 else return (_methodBase.CallingConvention | CallingConventions.VarArgs) != 0;
102 public LogicalCallContext LogicalCallContext {
104 if (_callCtx == null)
105 return LogicalCallContext.Empty;
111 public MethodBase MethodBase {
117 public string MethodName {
119 if (_methodBase != null && _methodName == null)
120 _methodName = _methodBase.Name;
125 public object MethodSignature {
127 if (_methodBase != null && _methodSignature == null) {
128 ParameterInfo[] parameters = _methodBase.GetParameters();
129 _methodSignature = new Type [parameters.Length];
130 for (int n=0; n<parameters.Length; n++)
131 _methodSignature[n] = parameters[n].ParameterType;
133 return _methodSignature;
137 public virtual IDictionary Properties {
139 if (_properties == null) _properties = new MethodReturnDictionary (this);
144 public string TypeName {
147 // lazily fill in _typeName from _methodBase
148 if (_methodBase != null && _typeName == null)
149 _typeName = _methodBase.DeclaringType.AssemblyQualifiedName;
165 public object GetArg (int arg_num)
167 return _args [arg_num];
170 public string GetArgName (int arg_num)
172 return _methodBase.GetParameters()[arg_num].Name;
175 public Exception Exception {
181 public int OutArgCount {
183 if (_args == null || _args.Length == 0) return 0;
184 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
185 return _inArgInfo.GetInOutArgCount ();
189 public object [] OutArgs {
191 if (_outArgs == null && _args != null) {
192 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
193 _outArgs = _inArgInfo.GetInOutArgs (_args);
199 public virtual object ReturnValue {
205 public object GetOutArg (int arg_num)
207 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
208 return _args[_inArgInfo.GetInOutArgIndex (arg_num)];
211 public string GetOutArgName (int arg_num)
213 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
214 return _inArgInfo.GetInOutArgName(arg_num);
217 Identity IInternalMessage.TargetIdentity
219 get { return _targetIdentity; }
220 set { _targetIdentity = value; }
223 public override string ToString ()
225 string s = TypeName.Split(',')[0] + "." + MethodName + " (";
226 if (_exception != null)
228 s += "Exception)\n" + _exception;
232 for (int n=0; n<OutArgs.Length; n++)
235 if (OutArgs[n] != null) s += OutArgs[n].GetType().Name + " ";
236 s += GetOutArgName (n);
237 if (OutArgs[n] != null) s += " = {" + OutArgs[n] + "}";