Share via


IDataContractSurrogate.GetDataContractType(Type) Metodo

Definizione

Durante la serializzazione, la deserializzazione e l'importazione ed esportazione dello schema, restituisce un tipo di contratto dati che sostituisce il tipo specificato.

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

Parametri

type
Type

Tipo CLR Type da sostituire.

Restituisce

Valore Type da sostituire con il valore type. Questo tipo deve poter essere serializzato da DataContractSerializer. Ad esempio, deve essere contrassegnato dall'attributo DataContractAttribute o tramite altri meccanismi riconosciuti dal serializzatore.

Esempio

Nel codice seguente viene illustrata un'implementazione del metodo GetDataContractType.

    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

Si applica a