Bewerken

Share via


DataContractResolver.ResolveName Method

Definition

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);
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

Parameters

typeName
String

The xsi:type name to map.

typeNamespace
String

The xsi:type namespace to map.

declaredType
Type

The type declared in the data contract.

knownTypeResolver
DataContractResolver

The known type resolver.

Returns

The type the xsi:type name and namespace is mapped to.

Examples

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;
    }
}

Remarks

If you want to use the known type resolution logic inside your implementation, a reference to it is passed in as the knownTypeResolver parameter.

Applies to