Export (0) Print
Expand All

IDataContractSurrogate Interface

Provides the methods needed to substitute one type for another by the DataContractSerializer during serialization, deserialization, and export and import of XML schema documents (XSD).

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

type IDataContractSurrogate =  interface end

The IDataContractSurrogate type exposes the following members.

Public methodGetCustomDataToExport(MemberInfo, Type)During schema export operations, inserts annotations into the schema for non-null return values.
Public methodGetCustomDataToExport(Type, Type)During schema export operations, inserts annotations into the schema for non-null return values.
Public methodGetDataContractTypeDuring serialization, deserialization, and schema import and export, returns a data contract type that substitutes the specified type.
Public methodGetDeserializedObjectDuring deserialization, returns an object that is a substitute for the specified object.
Public methodGetKnownCustomDataTypesSets the collection of known types to use for serialization and deserialization of the custom data objects.
Public methodGetObjectToSerializeDuring serialization, returns an object that substitutes the specified object.
Public methodGetReferencedTypeOnImportDuring schema import, returns the type referenced by the schema.
Public methodProcessImportedTypeProcesses the type that has been generated from the imported schema.

Use the IDataContractSurrogate when using the DataContractSerializer if you need to do one of the following: substitute one type or object for another, or to dynamically generate schema variations. For a sample application, see DataContract Surrogate Sample. For more information about data contracts, see Using Data Contracts.

At run time, you can find the specific DataContractSerializer for any operation in a service by using the OperationDescription to find the DataContractSerializerOperationBehavior instance. For more information about implementing the interface to create a surrogate, see Data Contract Surrogates.

You can also use the IDataContractSurrogate to affect the import and export of XML schemas when you are using the XsdDataContractExporter and XsdDataContractImporter classes. You can do so by assigning the IDataContractSurrogate to the DataContractSurrogate property of the ExportOptions class, or to the DataContractSurrogate property of the ImportOptions class. For more information, see Schema Import and Export.

The following example shows an implementation of the IDataContractSurrogate interface. The code substitutes the serialization of the Person type for a PersonSurrogated class.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2014 Microsoft