IDataContractSurrogate.GetDataContractType Method (Type)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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
)

Parameters

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
Available since 3.0
Return to top
Show: