System.Runtime.Remoting.Contexts.Context.SetProperty C# (CSharp) Méthode

SetProperty() private méthode

private SetProperty ( IContextProperty prop ) : void
prop IContextProperty
Résultat void
        public virtual void SetProperty(IContextProperty prop)
        {
            // We do not let people add properties to the default context.
            /* We allow appdomain level properties to be added to the default context
            if ((_ctxFlags & CTX_DEFAULT_CONTEXT) != 0)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AddContextFrozen"));
            }
            */
            
            if (prop == null || prop.Name == null)
            {
                throw new ArgumentNullException((prop==null) ? "prop" : "property name");
            }
    
            if ((_ctxFlags & CTX_FROZEN) != 0)
            {
                throw new InvalidOperationException(
                    Environment.GetResourceString("InvalidOperation_AddContextFrozen"));
            }
    
            lock (this)
            {
                // Check if we have a property by this name
                CheckPropertyNameClash(prop.Name, _ctxProps, _numCtxProps);
                
                // check if we need to grow the array.
                if (_ctxProps == null || _numCtxProps == _ctxProps.Length)    
                {
                    _ctxProps = GrowPropertiesArray(_ctxProps);
                }
                // now add the property
                _ctxProps[_numCtxProps++] = prop;
            }
        }
    

Usage Example

Exemple #1
0
        internal static Context CreateNewContext(IConstructionCallMessage msg)
        {
            // Create the new context

            Context newContext = new Context();

            foreach (IContextProperty prop in msg.ContextProperties)
            {
                if (newContext.GetProperty(prop.Name) == null)
                {
                    newContext.SetProperty(prop);
                }
            }
            newContext.Freeze();


            // Ask each context property whether the new context is OK

            foreach (IContextProperty prop in msg.ContextProperties)
            {
                if (!prop.IsNewContextOK(newContext))
                {
                    throw new RemotingException("A context property did not approve the candidate context for activating the object");
                }
            }

            return(newContext);
        }
All Usage Examples Of System.Runtime.Remoting.Contexts.Context::SetProperty