System.Runtime.Serialization.SurrogateSelector.GetSurrogate C# (CSharp) Method

GetSurrogate() public method

public GetSurrogate ( System type, System context, System &selector ) : System.Runtime.Serialization.ISerializationSurrogate
type System
context System
selector System
return System.Runtime.Serialization.ISerializationSurrogate
        public virtual System.Runtime.Serialization.ISerializationSurrogate GetSurrogate(System.Type type, System.Runtime.Serialization.StreamingContext context, out System.Runtime.Serialization.ISurrogateSelector selector) { throw null; }
        public virtual void RemoveSurrogate(System.Type type, System.Runtime.Serialization.StreamingContext context) { }

Usage Example

コード例 #1
0
		public static DiagramSerialize GetSurrogate(object graph, SurrogateSelector selector)
		{
			//Retrieve the surrogate reference
			//Sub classes may have added other surrogates
			//Start with the type of the deserialized data
			Type type = graph.GetType().UnderlyingSystemType;
			ISurrogateSelector iselector = (ISurrogateSelector) selector;
			DiagramSerialize surrogate = null;
			
			//Walk through the types until we find a surrogate
			while (type != typeof(System.Windows.Forms.UserControl))
			{
				surrogate = (DiagramSerialize) selector.GetSurrogate(type,new StreamingContext(StreamingContextStates.All),out iselector);
				if (surrogate != null) break;
				type = type.BaseType; //return the base type and try again
			}
			return surrogate;
		}