IDataContractSurrogate.GetDataContractType(Type) Método
Definição
Durante a serialização, desserialização e exportação e importação de esquemas, retorna um tipo de contrato de dados que substitui o tipo especificado.During serialization, deserialization, and schema import and export, returns a data contract type that substitutes the specified type.
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
Retornos
O Type a ser substituído para o valor type.The Type to substitute for the type value. Esse tipo deve ser serializável pelo DataContractSerializer.This type must be serializable by the DataContractSerializer. Por exemplo, ele deve ser marcado com o atributo DataContractAttribute ou outros mecanismos reconhecidos pelo serializador.For example, it must be marked with the DataContractAttribute attribute or other mechanisms that the serializer recognizes.
Exemplos
O exemplo a seguir mostra uma implementação do GetDataContractType método.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;
}
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