IDataContractSurrogate.GetDataContractType(Type) メソッド

定義

シリアル化、逆シリアル化、およびスキーマのインポートとエクスポートの間に、指定した型を置き換えるデータ コントラクト型を返します。

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

パラメーター

type
Type

置き換える CLR 型 Type

戻り値

Type 値を置き換えるための type。 この型は、DataContractSerializer によってシリアル化可能である必要があります。 たとえば、DataContractAttribute 属性でマークされているか、シリアライザーが認識できる他のメカニズムが使用されている必要があります。

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

適用対象