// Check whether we can cast the transparent proxy to the given type
        public bool CanCastTo(Type castType, Object o)
        {
            bool fCastOK = false;

            // The identity should be non-null
            BCLDebug.Assert(null != IdentityObject, "null != IdentityObject");

            Message.DebugOut("CheckCast for identity " + IdentityObject.GetType());

            if ((castType == s_typeofObject) ||
                (castType == s_typeofMarshalByRefObject))
            {
                return(true);
            }

            // Get the objref of the proxy
            ObjRef oRef = IdentityObject.ObjectRef;

            // If the object ref is non-null then check against the type info
            // stored in the it
            if (null != oRef)
            {
                Object oTP = GetTransparentProxy();

                // Check that there is a matching type in the server object
                // hierarchy represented in the objref
                Message.DebugOut("Calling CanCastTo for type " + castType);
                IRemotingTypeInfo typeInfo = oRef.TypeInfo;
                if (null != typeInfo)
                {
                    fCastOK = typeInfo.CanCastTo(castType, oTP);
                    if (!fCastOK && typeInfo.GetType() == typeof(TypeInfo) && oRef.IsWellKnown())
                    {
                        fCastOK = CanCastToWK(castType);
                    }
                }
                else
                {
                    if (oRef.IsObjRefLite())
                    {
                        // we should do a dynamic cast across the network
                        fCastOK = MarshalByRefObject.CanCastToXmlTypeHelper(castType, (MarshalByRefObject)o);
                    }
                }
            }
            // This is a well known object which does not have a backing ObjRef
            else
            {
                fCastOK = CanCastToWK(castType);
            }
            return(fCastOK);
        }
Exemplo n.º 2
0
        public bool CanCastTo(Type castType, object o)
        {
            if (castType == (Type)null)
            {
                throw new ArgumentNullException("castType");
            }
            RuntimeType castType1 = castType as RuntimeType;

            if (castType1 == (RuntimeType)null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            bool flag = false;

            if (castType1 == RemotingProxy.s_typeofObject || castType1 == RemotingProxy.s_typeofMarshalByRefObject)
            {
                return(true);
            }
            ObjRef objectRef = this.IdentityObject.ObjectRef;

            if (objectRef != null)
            {
                object            transparentProxy = this.GetTransparentProxy();
                IRemotingTypeInfo typeInfo         = objectRef.TypeInfo;
                if (typeInfo != null)
                {
                    flag = typeInfo.CanCastTo((Type)castType1, transparentProxy);
                    if (!flag && typeInfo.GetType() == typeof(System.Runtime.Remoting.TypeInfo) && objectRef.IsWellKnown())
                    {
                        flag = this.CanCastToWK((Type)castType1);
                    }
                }
                else if (objectRef.IsObjRefLite())
                {
                    flag = MarshalByRefObject.CanCastToXmlTypeHelper(castType1, (MarshalByRefObject)o);
                }
            }
            else
            {
                flag = this.CanCastToWK((Type)castType1);
            }
            return(flag);
        }
Exemplo n.º 3
0
        public bool CanCastTo(Type castType, object o)
        {
            if (castType == null)
            {
                throw new ArgumentNullException("castType");
            }
            RuntimeType fromType = castType as RuntimeType;

            if (fromType == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            bool flag = false;

            if ((fromType == s_typeofObject) || (fromType == s_typeofMarshalByRefObject))
            {
                return(true);
            }
            ObjRef objectRef = this.IdentityObject.ObjectRef;

            if (objectRef != null)
            {
                object            transparentProxy = this.GetTransparentProxy();
                IRemotingTypeInfo typeInfo         = objectRef.TypeInfo;
                if (typeInfo != null)
                {
                    flag = typeInfo.CanCastTo(fromType, transparentProxy);
                    if ((!flag && (typeInfo.GetType() == typeof(TypeInfo))) && objectRef.IsWellKnown())
                    {
                        flag = this.CanCastToWK(fromType);
                    }
                    return(flag);
                }
                if (objectRef.IsObjRefLite())
                {
                    flag = MarshalByRefObject.CanCastToXmlTypeHelper(fromType, (MarshalByRefObject)o);
                }
                return(flag);
            }
            return(this.CanCastToWK(fromType));
        }
Exemplo n.º 4
0
        // Check whether we can cast the transparent proxy to the given type
        public bool CanCastTo(Type castType, Object o)
        {
            bool fCastOK = false;

            // The identity should be non-null
            BCLDebug.Assert(null != IdentityObject, "null != IdentityObject");

            Message.DebugOut("CheckCast for identity " + IdentityObject.GetType());

            if ((castType == s_typeofObject) ||
                (castType == s_typeofMarshalByRefObject))
            {
                return(true);
            }

            // Get the objref of the proxy
            ObjRef oRef = IdentityObject.ObjectRef;

            // If the object ref is non-null then check against the type info
            // stored in the it
            if (null != oRef)
            {
                Object oTP = GetTransparentProxy();

                // Check that there is a matching type in the server object
                // hierarchy represented in the objref
                Message.DebugOut("Calling CanCastTo for type " + castType);
                IRemotingTypeInfo typeInfo = oRef.TypeInfo;
                if (null != typeInfo)
                {
                    fCastOK = typeInfo.CanCastTo(castType, oTP);
                }
                else
                {
                    if (oRef.IsObjRefLite())
                    {
                        // we should do a dynamic cast across the network
                        fCastOK = MarshalByRefObject.CanCastToXmlTypeHelper(castType, (MarshalByRefObject)o);
                    }
                }
            }
            // This is a well known object which does not have a backing ObjRef
            else
            {
                Message.DebugOut("CheckCast for well known objects and type " + castType);

                // Check whether the type to which we want to cast is
                // compatible with the current type
                if (castType.IsClass)
                {
                    fCastOK = GetProxiedType().IsAssignableFrom(castType);
                }
                else
                {
                    // NOTE: we are coming here also for x-context proxies
                    // when unmanaged code cannot determine if the cast is not
                    // okay
                    if (!(IdentityObject is ServerIdentity))
                    {
                        BCLDebug.Assert(
                            IdentityObject.URI != null,
                            "Bad WellKnown ID");
                        // Always allow interface casts to succeed. If the
                        // interface is not supported by the well known object
                        // then we will throw an exception when the interface
                        // is invoked.
                        fCastOK = true;
                    }
                }
            }

            return(fCastOK);
        }