예제 #1
0
        // Must return true if the context to serialize for (givenContext)
        // is a subset of the context for which the serialization selector is provided (presentContext)
        // Note: This is done by overriding KeyEquals rather than overriding Equals() in the SurrogateKey
        // class because Equals() method must be commutative.
        protected override bool KeyEquals(Object key, Object item)
        {
            SurrogateKey givenValue   = (SurrogateKey)item;
            SurrogateKey presentValue = (SurrogateKey)key;

            return(presentValue.m_type == givenValue.m_type &&
                   (presentValue.m_context.m_state & givenValue.m_context.m_state) == givenValue.m_context.m_state &&
                   presentValue.m_context.Context == givenValue.m_context.Context);
        }
예제 #2
0
        // Removes the surrogate associated with a given type.  Does not
        // check chained surrogates.
        public virtual void RemoveSurrogate(Type type, StreamingContext context)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            Contract.EndContractBlock();

            SurrogateKey key = new SurrogateKey(type, context);

            m_surrogates.Remove(key);
        }
예제 #3
0
        // Adds a surrogate to the list of surrogates checked.
        public virtual void AddSurrogate(Type type, StreamingContext context, ISerializationSurrogate surrogate)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (surrogate == null)
            {
                throw new ArgumentNullException("surrogate");
            }
            Contract.EndContractBlock();

            SurrogateKey key = new SurrogateKey(type, context);

            m_surrogates.Add(key, surrogate);  // Hashtable does duplicate checking.
        }
예제 #4
0
        // Gets the surrogate for a particular type.  If this selector can't
        // provide a surrogate, it checks with all of it's children before returning null.
        // [System.Security.SecurityCritical]  // auto-generated_required
        public virtual ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Contract.EndContractBlock();

            selector = this;

            SurrogateKey            key  = new SurrogateKey(type, context);
            ISerializationSurrogate temp = (ISerializationSurrogate)m_surrogates[key];

            if (temp != null)
            {
                return(temp);
            }
            if (m_nextSelector != null)
            {
                return(m_nextSelector.GetSurrogate(type, context, out selector));
            }
            return(null);
        }