SurrogateSelector::AddSurrogate Method (Type^, StreamingContext, ISerializationSurrogate^)

 

Adds a surrogate to the list of checked surrogates.

Namespace:   System.Runtime.Serialization
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual void AddSurrogate(
	Type^ type,
	StreamingContext context,
	ISerializationSurrogate^ surrogate
)

Parameters

type
Type: System::Type^

The Type for which the surrogate is required.

context
Type: System.Runtime.Serialization::StreamingContext

The context-specific data.

surrogate
Type: System.Runtime.Serialization::ISerializationSurrogate^

The surrogate to call for this type.

Exception Condition
ArgumentNullException

The type or surrogate parameter is null.

ArgumentException

A surrogate already exists for this type and context.

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.
SurrogateSelector 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());

.NET Framework
Available since 1.1
Return to top
Show: