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) { }
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; }