removed unused variables
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / MethodCall.cs
index 5ace8cd6573aefc7da06f583060c09bf928ad769..0ff8394f3380b49b7edbd8335299813893348cf4 100644 (file)
@@ -7,6 +7,29 @@
 // 2002 (C) Copyright, Ximian, Inc.
 //
 
+//
+// 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;
@@ -15,7 +38,7 @@ using System.Runtime.Serialization;
 namespace System.Runtime.Remoting.Messaging {
 
        [Serializable] [CLSCompliant (false)]
-       public class MethodCall : IMethodCallMessage, IMethodMessage, IMessage, ISerializable, IInternalMessage
+       public class MethodCall : IMethodCallMessage, IMethodMessage, IMessage, ISerializable, IInternalMessage, ISerializationRootObject
        {
                string _uri;
                string _typeName;
@@ -48,23 +71,21 @@ namespace System.Runtime.Remoting.Messaging {
 
                        foreach (SerializationEntry entry in info)
                                InitMethodProperty ((string)entry.Name, entry.Value);
-
-                       ResolveMethod ();
                }
 
                internal MethodCall (CADMethodCallMessage msg) 
                {
-                       _typeName = msg.TypeName;
-                       _uri = msg.Uri;
-                       _methodName = msg.MethodName;
+                       _uri = string.Copy (msg.Uri);
                        
                        // Get unmarshalled arguments
                        ArrayList args = msg.GetArguments ();
 
                        _args = msg.GetArgs (args);
-                       _methodSignature = (Type []) msg.GetMethodSignature (args);
+                       _callContext = msg.GetLogicalCallContext (args);
+                       if (_callContext == null)
+                               _callContext = new LogicalCallContext ();
        
-                       ResolveMethod ();
+                       _methodBase = MethodBase.GetMethodFromHandle (msg.MethodHandle);
                        Init();
 
                        if (msg.PropertiesCount > 0)
@@ -77,7 +98,6 @@ namespace System.Runtime.Remoting.Messaging {
                                CopyFrom ((IMethodMessage) msg);
                        else
                        {
-                               IDictionary dic = msg.Properties;
                                foreach (DictionaryEntry entry in msg.Properties)
                                        InitMethodProperty ((String) entry.Key, entry.Value);
                                Init();
@@ -149,9 +169,8 @@ namespace System.Runtime.Remoting.Messaging {
                        get { return _args; }
                }
                
-               [MonoTODO]
                public bool HasVarArgs {
-                       get { throw new NotImplementedException (); }
+                       get { return (MethodBase.CallingConvention | CallingConventions.VarArgs) != 0; }
                }
 
                public int InArgCount 
@@ -186,7 +205,12 @@ namespace System.Runtime.Remoting.Messaging {
                }
 
                public string MethodName {
-                       get { return _methodName; }
+                       get {
+                               // lazily fill in _methodName from _methodBase
+                               if (_methodName == null)
+                                       _methodName = _methodBase.Name;
+                               return _methodName;
+                       }
                }
 
                public object MethodSignature {
@@ -219,7 +243,12 @@ namespace System.Runtime.Remoting.Messaging {
 
                public string TypeName 
                {
-                       get { return _typeName; }
+                       get {
+                               // lazily fill in _typeName from _methodBase
+                               if (_typeName == null)
+                                       _typeName = _methodBase.DeclaringType.AssemblyQualifiedName;
+                               return _typeName;
+                       }
                }
 
                public string Uri {
@@ -264,12 +293,10 @@ namespace System.Runtime.Remoting.Messaging {
                        if (_uri != null)
                        {
                                Type type = RemotingServices.GetServerTypeForUri (_uri);
+                               if (type == null) throw new RemotingException ("Requested service not found. No receiver for uri " + _uri);
 
-                               if (CanCastTo (_typeName, type))
-                               {
-                                       BindingFlags bflags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
-                                       if (_methodSignature == null) _methodBase = type.GetMethod (_methodName, bflags);
-                                       else _methodBase = type.GetMethod (_methodName, bflags, null, _methodSignature, null);
+                               if (CanCastTo (_typeName, type)) {
+                                       _methodBase = RemotingServices.GetMethodBaseFromName (type, _methodName, _methodSignature);
                                        return;
                                }
                                else
@@ -278,9 +305,9 @@ namespace System.Runtime.Remoting.Messaging {
                        _methodBase = RemotingServices.GetMethodBaseFromMethodMessage (this);
                }
 
-               public bool CanCastTo (string clientType, Type serverType)
+               bool CanCastTo (string clientType, Type serverType)
                {
-                       int i = clientType.IndexOf(",");
+                       int i = clientType.IndexOf(',');
                        if (i != -1) clientType = clientType.Substring (0,i).Trim();
 
                        if (clientType == serverType.FullName) return true;