SurrogateSelector.AddSurrogate(Type, StreamingContext, ISerializationSurrogate) SurrogateSelector.AddSurrogate(Type, StreamingContext, ISerializationSurrogate) SurrogateSelector.AddSurrogate(Type, StreamingContext, ISerializationSurrogate) Method

Definition

Adds a surrogate to the list of checked surrogates.

public:
 virtual void AddSurrogate(Type ^ type, System::Runtime::Serialization::StreamingContext context, System::Runtime::Serialization::ISerializationSurrogate ^ surrogate);
public virtual void AddSurrogate (Type type, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISerializationSurrogate surrogate);
abstract member AddSurrogate : Type * System.Runtime.Serialization.StreamingContext * System.Runtime.Serialization.ISerializationSurrogate -> unit
override this.AddSurrogate : Type * System.Runtime.Serialization.StreamingContext * System.Runtime.Serialization.ISerializationSurrogate -> unit

Parameters

type
Type Type Type

The Type for which the surrogate is required.

context
StreamingContext StreamingContext StreamingContext

The context-specific data.

surrogate
ISerializationSurrogate ISerializationSurrogate ISerializationSurrogate

The surrogate to call for this type.

Exceptions

The type or surrogate parameter is null.

A surrogate already exists for this type and context.

Examples

The following code example demonstrates calling the AddSurrogate method. This code example is part of a larger example provided for the SurrogateSelector class.

// Create a SurrogateSelector.
var ss = new SurrogateSelector();

// Tell the SurrogateSelector that Employee objects are serialized and deserialized 
// using the EmployeeSerializationSurrogate object.
ss.AddSurrogate(typeof(Employee),
new StreamingContext(StreamingContextStates.All),
new EmployeeSerializationSurrogate());

Applies to