IDataContractSurrogate.GetDataContractType(Type) Método

Definición

Durante la serialización, la deserialización y la importación y exportación de esquemas, devuelve un tipo de contrato de datos que sustituye al tipo especificado.

public:
 Type ^ GetDataContractType(Type ^ type);
public Type GetDataContractType(Type type);
abstract member GetDataContractType : Type -> Type
Public Function GetDataContractType (type As Type) As Type

Parámetros

type
Type

Tipo CLR Type que se va a sustituir.

Devoluciones

que Type se va a sustituir por el type valor. Este tipo debe ser serializable por .DataContractSerializer Por ejemplo, debe marcarse con el DataContractAttribute atributo u otros mecanismos que reconoce el serializador.

Ejemplos

En el ejemplo siguiente se muestra una implementación del GetDataContractType método .

    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;
    }
Public Function GetDataContractType(ByVal type As Type) As Type _
   Implements IDataContractSurrogate.GetDataContractType
    Console.WriteLine("GetDataContractType invoked")
    Console.WriteLine(vbTab & "type name: {0}", type.Name)
    ' "Person" will be serialized as "PersonSurrogated"
    ' This method is called during serialization,
    ' deserialization, and schema export.
    If GetType(Person).IsAssignableFrom(type) Then
        Console.WriteLine(vbTab & "returning PersonSurrogated")
        Return GetType(PersonSurrogated)
    End If
    Return type

End Function

Se aplica a