2008-01-15 Stephane Delcroix <sdelcroix@novell.com>
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / ReturnMessage.cs
index 0659c0bf0007fe0157c22c0ea0743f0d40fc5b95..aee39f5bb81103129491a363a4e1641fd44a3d56 100644 (file)
@@ -7,15 +7,40 @@
 // (C) Ximian, Inc.  http://www.ximian.com
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Collections;
 using System.Reflection;
 using System.IO;
 
-namespace System.Runtime.Remoting.Messaging {
-
-       [Serializable]
-       public class ReturnMessage : IMethodReturnMessage, IMethodMessage, IInternalMessage 
+namespace System.Runtime.Remoting.Messaging 
+{
+#if NET_2_0
+       [System.Runtime.InteropServices.ComVisible (true)]
+#endif
+       public class ReturnMessage : IMethodReturnMessage, IMethodMessage, IMessage, IInternalMessage 
        {
                object[] _outArgs;
                object[] _args;
@@ -26,7 +51,7 @@ namespace System.Runtime.Remoting.Messaging {
                Exception _exception;
                MethodBase _methodBase;
                string _methodName;
-               object _methodSignature;
+               Type [] _methodSignature;
                string _typeName;
                MethodReturnDictionary _properties;
                Identity _targetIdentity;
@@ -42,11 +67,10 @@ namespace System.Runtime.Remoting.Messaging {
                        _args = outArgs;
                        _outArgsCount = outArgCount;
                        _callCtx = callCtx;
-                       _uri = request.Uri;
-                       _methodBase = request.MethodBase;
-                       _methodName = request.MethodName;
-                       _methodSignature = request.MethodSignature;
-                       _typeName = request.TypeName;
+                       if (request != null) {
+                               _uri = request.Uri;
+                               _methodBase = request.MethodBase;
+                       }
                        if (_args == null) _args = new object [outArgCount];
                }
 
@@ -54,12 +78,9 @@ namespace System.Runtime.Remoting.Messaging {
                {
                        _exception = exc;
                        
-                       if (request != null)
-                       {
+                       if (request != null) {
                                _methodBase = request.MethodBase;
-                               _methodName = request.MethodName;
-                               _methodSignature = request.MethodSignature;
-                               _typeName = request.TypeName;
+                               _callCtx = request.LogicalCallContext;
                        }
                        _args = new object[0];  // .NET does this
                }
@@ -78,12 +99,15 @@ namespace System.Runtime.Remoting.Messaging {
                
                public bool HasVarArgs {
                        get {
-                               return false;   //todo: complete
+                               if (_methodBase == null) return false;
+                               else return (_methodBase.CallingConvention | CallingConventions.VarArgs) != 0;
                        }
                }
 
                public LogicalCallContext LogicalCallContext {
                        get {
+                               if (_callCtx == null)
+                                       _callCtx = new LogicalCallContext ();
                                return _callCtx;
                        }
                }
@@ -96,13 +120,20 @@ namespace System.Runtime.Remoting.Messaging {
 
                public string MethodName {
                        get {
+                               if (_methodBase != null && _methodName == null)
+                                       _methodName = _methodBase.Name;
                                return _methodName;
-
                        }
                }
 
                public object MethodSignature {
                        get {
+                               if (_methodBase != null && _methodSignature == null) {
+                                       ParameterInfo[] parameters = _methodBase.GetParameters();
+                                       _methodSignature = new Type [parameters.Length];
+                                       for (int n=0; n<parameters.Length; n++)
+                                               _methodSignature[n] = parameters[n].ParameterType;
+                               }
                                return _methodSignature;
                        }
                }
@@ -116,7 +147,12 @@ namespace System.Runtime.Remoting.Messaging {
 
                public string TypeName {
                        get {
+
+                               // lazily fill in _typeName from _methodBase
+                               if (_methodBase != null && _typeName == null)
+                                       _typeName = _methodBase.DeclaringType.AssemblyQualifiedName;
                                return _typeName;
+
                        }
                }
 
@@ -130,6 +166,11 @@ namespace System.Runtime.Remoting.Messaging {
                        }
                }
 
+               string IInternalMessage.Uri {
+                       get { return Uri; }
+                       set { Uri = value; }
+               }
+
                public object GetArg (int arg_num)
                {
                        return _args [arg_num];
@@ -148,7 +189,7 @@ namespace System.Runtime.Remoting.Messaging {
 
                public int OutArgCount {
                        get {
-                               if (_args.Length == 0) return 0;
+                               if (_args == null || _args.Length == 0) return 0;
                                if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
                                return _inArgInfo.GetInOutArgCount ();
                        }
@@ -156,9 +197,9 @@ namespace System.Runtime.Remoting.Messaging {
 
                public object [] OutArgs {
                        get {
-                               if (_outArgs == null) {
-                                       _outArgs = new object [OutArgCount];
-                                       Array.Copy (_args, _outArgs, OutArgCount);
+                               if (_outArgs == null && _args != null) {
+                                       if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
+                                       _outArgs = _inArgInfo.GetInOutArgs (_args);
                                }                                       
                                return _outArgs;
                        }
@@ -172,7 +213,8 @@ namespace System.Runtime.Remoting.Messaging {
 
                public object GetOutArg (int arg_num)
                {
-                       return _args[arg_num];
+                       if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
+                       return _args[_inArgInfo.GetInOutArgIndex (arg_num)];
                }
 
                public string GetOutArgName (int arg_num)
@@ -187,9 +229,10 @@ namespace System.Runtime.Remoting.Messaging {
                        set { _targetIdentity = value; }
                }
 
+#if !NET_2_0
                public override string ToString ()
                {
-                       string s = _typeName.Split(',')[0] + "." + _methodName + " (";
+                       string s = TypeName.Split(',')[0] + "." + MethodName + " (";
                        if (_exception != null)
                        {
                                s += "Exception)\n" + _exception;
@@ -208,5 +251,6 @@ namespace System.Runtime.Remoting.Messaging {
                        }
                        return s;
                }
+#endif
        }
 }