Share via


IDataContractSurrogate.GetDataContractType(Type) 메서드

정의

serialization, deserialization 및 스키마 가져오기/내보내기 중에 지정한 형식을 대체하는 데이터 계약 형식을 반환합니다.

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를 사용하여 serialize할 수 있어야 합니다. 예를 들어, DataContractAttribute 특성 또는 serializer가 인식하는 기타 메커니즘으로 표시해야 합니다.

예제

다음 예제에서는 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

적용 대상