This documentation is archived and is not being maintained.

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, 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.