Export (0) Print
Expand All

DataContractResolver.ResolveName Method

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

Namespace:  System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

public abstract Type ResolveName(
	string typeName,
	string typeNamespace,
	Type declaredType,
	DataContractResolver knownTypeResolver
)

Parameters

typeName
Type: System.String

The xsi:type name to map.

typeNamespace
Type: System.String

The xsi:type namespace to map.

declaredType
Type: System.Type

The type declared in the data contract.

knownTypeResolver
Type: System.Runtime.Serialization.DataContractResolver

The known type resolver.

Return Value

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

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

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

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft