コード例 #1
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object Wrap(ContextBoundObject obj, Object proxy, bool fCreateSinks) 
        {
            Message.DebugOut("Entering Wrap for context " + Thread.CurrentContext + "\n");

            if ((null != obj) && (!IsTransparentProxy(obj))) 
            {
                Contract.Assert(obj.GetType().IsContextful,"objType.IsContextful"); 
                Message.DebugOut("Wrapping object \n"); 
                Identity idObj = null;
 
                if (proxy != null)
                {
                    // We will come here for strictly x-context activations
                    // since a proxy has already been created and supplied 
                    // through the construction message frame (GetThisPtr()).
                    RealProxy rp = GetRealProxy(proxy); 
                    if (rp.UnwrappedServerObject == null) 
                    {
                        rp.AttachServerHelper(obj); 
                    }
                    idObj = MarshalByRefObject.GetIdentity(obj);
                }
                else 
                {
                    // Proxy is null when Wrap() is called the second 
                    // time during activation 
                    // It also will be null when a ContextBoundObject
                    // is being activated from a remote client. 
                    idObj = IdentityHolder.FindOrCreateServerIdentity(
                                obj,
                                null,
                                IdOps.None); 
                }
 
                //********************WARNING******************************* 
                // Always create the proxy before calling out to user code
                // so that any recursive calls by JIT to wrap will return this 
                // proxy.
                //**********************************************************
                // Get the proxy represented by the identity object
                proxy = GetOrCreateProxy(idObj, proxy, true); 

                // EXTENSIBILITY: 
                GetRealProxy(proxy).Wrap(); 

                if (fCreateSinks) 
                {
                    IMessageSink chnlSink = null;
                    IMessageSink envoySink = null;
                    // Create the envoy sinks and channel sink 
                    CreateEnvoyAndChannelSinks((MarshalByRefObject)proxy, null, out chnlSink, out envoySink);
 
                    // Set the envoy and channel sinks in a thread safe manner 
                    SetEnvoyAndChannelSinks(idObj, chnlSink, envoySink);
                } 

                // This will handle the case where we call Wrap() with
                // a null proxy for real remote activation of ContextFul types.
                RealProxy rp2 = GetRealProxy(proxy); 
                if (rp2.UnwrappedServerObject == null)
                { 
                    rp2.AttachServerHelper(obj); 
                }
                Message.DebugOut("Leaving Wrap with proxy \n"); 
                return proxy;
            }
            else
            { 
                Message.DebugOut("Leaving Wrap with passed in object\n");
 
                // Default return value is the object itself 
                return obj;
            } 
        } // Wrap