Exemplo n.º 1
0
        public virtual ISerializationSurrogate GetSurrogate(Type type,
                                                            StreamingContext context, out ISurrogateSelector selector)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type is null.");
            }

            // Check this selector, and if the surrogate is not found,
            // check the chained selectors

            string key = type.FullName + "#" + context.ToString();
            ISerializationSurrogate surrogate = (ISerializationSurrogate)Surrogates [key];

            if (surrogate != null)
            {
                selector = this;
                return(surrogate);
            }

            if (nextSelector != null)
            {
                return(nextSelector.GetSurrogate(type, context, out selector));
            }
            else
            {
                selector = null;
                return(null);
            }
        }
        /// <summary>Removes the surrogate associated with a given type.</summary>
        /// <param name="type">The <see cref="T:System.Type" /> for which to remove the surrogate. </param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> for the current surrogate. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="type" /> parameter is null. </exception>
        public virtual void RemoveSurrogate(Type type, StreamingContext context)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type is null.");
            }
            string key = type.FullName + "#" + context.ToString();

            this.Surrogates.Remove(key);
        }
Exemplo n.º 3
0
		// Methods
		public virtual void AddSurrogate (Type type,
			  StreamingContext context, ISerializationSurrogate surrogate)
		{
			if (type == null || surrogate == null)
				throw new ArgumentNullException ("Null reference.");

			string currentKey = type.FullName + "#" + context.ToString ();

			if (Surrogates.ContainsKey (currentKey))
				throw new ArgumentException ("A surrogate for " + type.FullName + " already exists.");

			Surrogates.Add (currentKey, surrogate);
		}
        /// <summary>Adds a surrogate to the list of checked surrogates.</summary>
        /// <param name="type">The <see cref="T:System.Type" /> for which the surrogate is required.</param>
        /// <param name="context">The context-specific data. </param>
        /// <param name="surrogate">The surrogate to call for this type. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="type" /> or <paramref name="surrogate" /> parameter is null. </exception>
        /// <exception cref="T:System.ArgumentException">A surrogate already exists for this type and context. </exception>
        public virtual void AddSurrogate(Type type, StreamingContext context, ISerializationSurrogate surrogate)
        {
            if (type == null || surrogate == null)
            {
                throw new ArgumentNullException("Null reference.");
            }
            string key = type.FullName + "#" + context.ToString();

            if (this.Surrogates.ContainsKey(key))
            {
                throw new ArgumentException("A surrogate for " + type.FullName + " already exists.");
            }
            this.Surrogates.Add(key, surrogate);
        }
        /// <summary>Returns the surrogate for a particular type.</summary>
        /// <returns>The surrogate for a particular type.</returns>
        /// <param name="type">The <see cref="T:System.Type" /> for which the surrogate is requested. </param>
        /// <param name="context">The streaming context. </param>
        /// <param name="selector">The surrogate to use. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="type" /> parameter is null. </exception>
        /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" />
        /// </PermissionSet>
        public virtual ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type is null.");
            }
            string key = type.FullName + "#" + context.ToString();
            ISerializationSurrogate serializationSurrogate = (ISerializationSurrogate)this.Surrogates[key];

            if (serializationSurrogate != null)
            {
                selector = this;
                return(serializationSurrogate);
            }
            if (this.nextSelector != null)
            {
                return(this.nextSelector.GetSurrogate(type, context, out selector));
            }
            selector = null;
            return(null);
        }
Exemplo n.º 6
0
		public virtual ISerializationSurrogate GetSurrogate (Type type,
			     StreamingContext context, out ISurrogateSelector selector)
		{
			if (type == null)
				throw new ArgumentNullException ("type is null.");

			// Check this selector, and if the surrogate is not found,
			// check the chained selectors
			
			string key = type.FullName + "#" + context.ToString ();			
			ISerializationSurrogate surrogate = (ISerializationSurrogate) Surrogates [key];

			if (surrogate != null) {
				selector = this;
				return surrogate;
			}
			
			if (nextSelector != null)
				return nextSelector.GetSurrogate (type, context, out selector);
			else {
				selector = null;
				return null;
			}
		}
Exemplo n.º 7
0
		public virtual void RemoveSurrogate (Type type, StreamingContext context)
		{
			if (type == null)
				throw new ArgumentNullException ("type is null.");

			string key = type.FullName + "#" + context.ToString ();
			Surrogates.Remove (key);
		}