System.Runtime.Remoting.RemotingServices.IsClientProxy C# (CSharp) Méthode

IsClientProxy() static private méthode

static private IsClientProxy ( Object obj ) : bool
obj Object
Résultat bool
        internal static bool IsClientProxy(Object obj)
        {
            MarshalByRefObject mbr = obj as MarshalByRefObject;
            if (mbr == null)
                return false;
        
            bool bIsClientProxy = false;
        
            bool fServer;
            Identity id = MarshalByRefObject.GetIdentity(mbr, out fServer);
            // If the identity is null, this is defintely a locally hosted object;
            // otherwise...(see if statement below).
            if (id != null)
            {
                if (!(id is ServerIdentity))
                    bIsClientProxy = true;
            }

            return bIsClientProxy;
        } // IsClientProxy
         

Usage Example

 internal ServerIdentity StartupWellKnownObject(string asmName, string svrTypeName, string URI, WellKnownObjectMode mode, bool fReplace)
 {
     lock (s_wkoStartLock)
     {
         MarshalByRefObject obj2     = null;
         ServerIdentity     identity = null;
         Type type = LoadType(svrTypeName, asmName);
         if (!type.IsMarshalByRef)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_WellKnown_MustBeMBR", new object[] { svrTypeName }));
         }
         identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
         if ((identity != null) && identity.IsRemoteDisconnected())
         {
             IdentityHolder.RemoveIdentity(URI);
             identity = null;
         }
         if (identity == null)
         {
             s_fullTrust.Assert();
             try
             {
                 obj2 = (MarshalByRefObject)Activator.CreateInstance(type, true);
                 if (RemotingServices.IsClientProxy(obj2))
                 {
                     RedirectionProxy proxy = new RedirectionProxy(obj2, type)
                     {
                         ObjectMode = mode
                     };
                     RemotingServices.MarshalInternal(proxy, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else if (type.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                 {
                     ComRedirectionProxy proxy2 = new ComRedirectionProxy(obj2, type);
                     RemotingServices.MarshalInternal(proxy2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else
                 {
                     if (RemotingServices.GetObjectUri(obj2) != null)
                     {
                         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), new object[] { URI }));
                     }
                     RemotingServices.MarshalInternal(obj2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     if (mode == WellKnownObjectMode.SingleCall)
                     {
                         identity.SetSingleCallObjectMode();
                     }
                     else
                     {
                         identity.SetSingletonObjectMode();
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
             }
         }
         return(identity);
     }
 }
RemotingServices