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

System_CAPS_pubmethodGetCustomDataToExport(MemberInfo, Type)

During schema export operations, inserts annotations into the schema for non-null return values.

System_CAPS_pubmethodGetCustomDataToExport(Type, Type)

During schema export operations, inserts annotations into the schema for non-null return values.


During serialization, deserialization, and schema import and export, returns a data contract type that substitutes the specified type.

System_CAPS_pubmethodGetDeserializedObject(Object, Type)

During deserialization, returns an object that is a substitute for the specified object.


Sets the collection of known types to use for serialization and deserialization of the custom data objects.

System_CAPS_pubmethodGetObjectToSerialize(Object, Type)

During serialization, returns an object that substitutes the specified object.

System_CAPS_pubmethodGetReferencedTypeOnImport(String, String, Object)

During schema import, returns the type referenced by the schema.

System_CAPS_pubmethodProcessImportedType(CodeTypeDeclaration, CodeCompileUnit)

Processes 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. 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
Available since 3.0
Return to top