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(String, String, Type, DataContractResolver) 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

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft