Export (0) Print
Expand All

IDataContractSurrogate.GetDataContractType Method

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

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

Type GetDataContractType(
	Type type


Type: System.Type

The CLR type Type to substitute.

Return Value

Type: System.Type
The Type to substitute for the type value. This type must be serializable by the DataContractSerializer. For example, it must be marked with the DataContractAttribute attribute or other mechanisms that the serializer recognizes.

The following example shows an implementation of the GetDataContractType method.

    public Type GetDataContractType(Type type) 
        Console.WriteLine("GetDataContractType invoked");
        Console.WriteLine("\t type name: {0}", type.Name);
        // "Person" will be serialized as "PersonSurrogated" 
        // This method is called during serialization, 
        // deserialization, and schema export. 
        if (typeof(Person).IsAssignableFrom(type)) 
Console.WriteLine("\t returning PersonSurrogated");
            return typeof(PersonSurrogated);
        return type;


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft