DataContractResolver.ResolveName(String, String, Type, DataContractResolver) DataContractResolver.ResolveName(String, String, Type, DataContractResolver) DataContractResolver.ResolveName(String, String, Type, DataContractResolver) DataContractResolver.ResolveName(String, String, Type, DataContractResolver) Method

定義

覆寫這個方法,以便在還原序列化期間,將指定的 xsi:type 名稱和命名空間對應至資料合約型別。Override this method to map the specified xsi:type name and namespace to a data contract type during deserialization.

public:
 abstract Type ^ ResolveName(System::String ^ typeName, System::String ^ typeNamespace, Type ^ declaredType, System::Runtime::Serialization::DataContractResolver ^ knownTypeResolver);
public abstract Type ResolveName (string typeName, string typeNamespace, Type declaredType, System.Runtime.Serialization.DataContractResolver knownTypeResolver);
abstract member ResolveName : string * string * Type * System.Runtime.Serialization.DataContractResolver -> Type
Public MustOverride Function ResolveName (typeName As String, typeNamespace As String, declaredType As Type, knownTypeResolver As DataContractResolver) As Type

參數

typeName
String String String String

要對應的 xsi:type 名稱。The xsi:type name to map.

typeNamespace
String String String String

要對應的 xsi:type 命名空間。The xsi:type namespace to map.

declaredType
Type Type Type Type

在資料合約中宣告的型別。The type declared in the data contract.

knownTypeResolver
DataContractResolver DataContractResolver DataContractResolver DataContractResolver

已知的型別解析程式。The known type resolver.

傳回

xsi:type 名稱和命名空間所對應的型別。The type the xsi:type name and namespace is mapped to.

範例

下列範例會示範 ResolveName 方法的實作。The following example shows an implementation of the ResolveName method.

// Used at deserialization
// Allows users to map xsi:type name to any Type 
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
    XmlDictionaryString tName;
    XmlDictionaryString tNamespace;
    if (dictionary.TryGetValue(typeName, out tName) && dictionary.TryGetValue(typeNamespace, out tNamespace))
    {
        return this.assembly.GetType(tNamespace.Value + "." + tName.Value);
    }
    else
    {
        return null;
    }
}

備註

如果您要在實作內使用已知的型別解析邏輯,其參考會當做 knownTypeResolver 參數傳入。If you want to use the known type resolution logic inside your implementation, a reference to it is passed in as the knownTypeResolver parameter.

適用於