DataContractResolver.TryResolveType メソッド

定義

シリアル化中にデータ コントラクト型を 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 名前空間。

返品

true マッピングが成功した場合。それ以外の場合は false

次の例は、 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 パラメーターとして渡されます。

適用対象