* RealProxy.cs: Added new internal method for getting the proxy type. It
authorLluis Sanchez <lluis@novell.com>
Fri, 5 Mar 2004 03:52:13 +0000 (03:52 -0000)
committerLluis Sanchez <lluis@novell.com>
Fri, 5 Mar 2004 03:52:13 +0000 (03:52 -0000)
  gets the proxy type from the MonoRemoteClass (it can change if the
  vtable is upgraded).
  Modified GetTransparentProxy(). Now it takes the name of the type.
  The name is taken from the IRemotingTypeInfo object.
* RemotingProxy.cs: The class must implement IRemotingTypeInfo.

svn path=/trunk/mcs/; revision=23731

mcs/class/corlib/System.Runtime.Remoting.Proxies/ChangeLog
mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs
mcs/class/corlib/System.Runtime.Remoting.Proxies/RemotingProxy.cs

index dcdcd086fc0545efea436dd857c59ac4573eb6ab..06cd6c6f262ebbd69ea7671cee9901f81ccfa3ce 100644 (file)
@@ -1,3 +1,12 @@
+2004-03-04  Lluis Sanchez Gual  <lluis@ximian.com>
+
+       * RealProxy.cs: Added new internal method for getting the proxy type. It
+         gets the proxy type from the MonoRemoteClass (it can change if the
+         vtable is upgraded).
+         Modified GetTransparentProxy(). Now it takes the name of the type.
+         The name is taken from the IRemotingTypeInfo object.
+       * RemotingProxy.cs: The class must implement IRemotingTypeInfo.
+
 2004-01-19  Lluis Sanchez Gual  <lluis@ximian.com>
 
        * RealProxy.cs: Added setter for ObjectIdentity.
index 84eb8823ca95a62f6ad5a4d43f4b81478d037b62..44ba617ee4a956fecab24121365fbd6c6d7f138a 100644 (file)
@@ -58,13 +58,18 @@ namespace System.Runtime.Remoting.Proxies
                        this.class_to_proxy = classToProxy;
 
                        // TODO: Fix stub
-                       _objTP = InternalGetTransparentProxy();
                }
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern static Type InternalGetProxyType (object transparentProxy);
+               
                public Type GetProxiedType() 
                {
-                       if (class_to_proxy.IsInterface) return typeof (MarshalByRefObject);
-                       else return class_to_proxy;
+                       if (_objTP == null) {
+                               if (class_to_proxy.IsInterface) return typeof(MarshalByRefObject);
+                               else return class_to_proxy;
+                       }
+                       return InternalGetProxyType (_objTP);
                }
 
                public virtual ObjRef CreateObjRef (Type requestedType)
@@ -124,8 +129,9 @@ namespace System.Runtime.Remoting.Proxies
                        if (mMsg.CallType == CallType.BeginInvoke) 
                                mMsg.AsyncResult.CallMessage = mMsg;    // TODO: do this in the runtime
 
-                       IMethodReturnMessage res_msg = (IMethodReturnMessage)rp.Invoke (msg);
-
+                       IMethodReturnMessage res_msg = null;
+                       res_msg = (IMethodReturnMessage)rp.Invoke (msg);
+                       
                        if (res_msg.LogicalCallContext != null && res_msg.LogicalCallContext.HasInfo)
                                CallContext.UpdateCurrentCallContext (res_msg.LogicalCallContext);
 
@@ -153,10 +159,25 @@ namespace System.Runtime.Remoting.Proxies
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal extern virtual object InternalGetTransparentProxy ();
+               internal extern virtual object InternalGetTransparentProxy (string className);
 
                public virtual object GetTransparentProxy () 
                {
+                       if (_objTP == null) 
+                       {
+                               string name;
+                               IRemotingTypeInfo rti = this as IRemotingTypeInfo;
+                               
+                               if (rti != null) {
+                                       name = rti.TypeName;
+                                       if (name == typeof(MarshalByRefObject).AssemblyQualifiedName)
+                                               name = class_to_proxy.AssemblyQualifiedName;
+                               }
+                               else
+                                       name = class_to_proxy.AssemblyQualifiedName;
+                                       
+                               _objTP = InternalGetTransparentProxy (name);
+                       }
                        return _objTP;
                }
 
index 52a7dce3faed710cfaeeee2863be7d6d536245a6..727bc6e97390beab3e12e43a20283b7cc44532f0 100644 (file)
@@ -21,7 +21,7 @@ using System.Threading;
 namespace System.Runtime.Remoting.Proxies
 {
 
-       internal class RemotingProxy : RealProxy 
+       internal class RemotingProxy : RealProxy, IRemotingTypeInfo
        {
                static MethodInfo _cache_GetTypeMethod = typeof(System.Object).GetMethod("GetType");
                static MethodInfo _cache_GetHashCodeMethod = typeof(System.Object).GetMethod("GetHashCode");
@@ -127,6 +127,32 @@ namespace System.Runtime.Remoting.Proxies
                        _ctorCall.CopyFrom (request);
                        return ActivationServices.Activate (this, _ctorCall);
                }
+
+               public string TypeName 
+               { 
+                       get
+                       {
+                               if (_objectIdentity is ClientIdentity) {
+                                       ObjRef oref = _objectIdentity.CreateObjRef (null);
+                                       if (oref.TypeInfo != null) return oref.TypeInfo.TypeName;
+                               }
+                               return GetProxiedType().AssemblyQualifiedName;
+                       }
+                       
+                       set
+                       {
+                               throw new NotSupportedException ();
+                       }
+               }
+               
+               public bool CanCastTo (Type fromType, object o)
+               {
+                       if (_objectIdentity is ClientIdentity) {
+                               ObjRef oref = _objectIdentity.CreateObjRef (null);
+                               if (oref.TypeInfo != null) return oref.TypeInfo.CanCastTo (fromType, o);
+                       }
+                       return fromType.IsAssignableFrom (GetProxiedType());
+               }
                
                ~RemotingProxy()
                {