DataContractResolver.TryResolveType 메서드

정의

serialization 중에 데이터 계약 형식을 이름 및 네임스페이스에 매핑하려면 이 메서드를 재정의 xsi:type 합니다.

public:
 abstract bool TryResolveType(Type ^ type, Type ^ declaredType, System::Runtime::Serialization::DataContractResolver ^ knownTypeResolver, [Runtime::InteropServices::Out] System::Xml::XmlDictionaryString ^ % typeName, [Runtime::InteropServices::Out] System::Xml::XmlDictionaryString ^ % typeNamespace);
public abstract bool TryResolveType(Type type, Type declaredType, System.Runtime.Serialization.DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace);
abstract member TryResolveType : Type * Type * System.Runtime.Serialization.DataContractResolver * XmlDictionaryString * XmlDictionaryString -> bool
Public MustOverride Function TryResolveType (type As Type, declaredType As Type, knownTypeResolver As DataContractResolver, ByRef typeName As XmlDictionaryString, ByRef typeNamespace As XmlDictionaryString) As Boolean

매개 변수

type
Type

매핑할 형식입니다.

declaredType
Type

데이터 계약에 선언된 형식입니다.

knownTypeResolver
DataContractResolver

알려진 형식 확인자입니다.

typeName
XmlDictionaryString

xsi:type 이름입니다.

typeNamespace
XmlDictionaryString

xsi:type 네임스페이스입니다.

반품

매핑에 성공하면

예제

다음 예제에서는 메서드의 구현을 TryResolveType 보여줍니다.

// Used at serialization
// Maps any Type to a new xsi:type representation
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
    string name = type.Name;
    string namesp = type.Namespace;
    typeName = new XmlDictionaryString(XmlDictionary.Empty, name, 0);
    typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, namesp, 0);
    if (!dictionary.ContainsKey(type.Name))
    {
        dictionary.Add(name, typeName);
    }
    if (!dictionary.ContainsKey(type.Namespace))
    {
        dictionary.Add(namesp, typeNamespace);
    }
    return true;
}

설명

구현 내에서 알려진 형식 확인 논리를 사용하려는 경우 이 논리에 대한 참조가 매개 변수로 knownTypeResolver 전달됩니다.

적용 대상