DataContractResolver.ResolveName Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Override this method to map the specified xsi:type name and namespace to a data contract type during deserialization.

C#
public abstract Type ResolveName(string typeName, string typeNamespace, Type declaredType, System.Runtime.Serialization.DataContractResolver knownTypeResolver);
C#
public abstract Type? ResolveName(string typeName, string? typeNamespace, Type? declaredType, System.Runtime.Serialization.DataContractResolver knownTypeResolver);

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.

C#
// 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

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0