DataContractResolver.ResolveName Metodo

Definizione

Eseguire l'override di questo metodo per eseguire il mapping del nome e dello spazio dei nomi specificati xsi:type a un tipo di contratto dati durante la deserializzazione.

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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
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);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
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
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
abstract member ResolveName : string * string * Type * System.Runtime.Serialization.DataContractResolver -> Type
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
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

Parametri

typeName
String

Nome xsi:type di cui eseguire il mapping.

typeNamespace
String

Spazio xsi:type dei nomi di cui eseguire il mapping.

declaredType
Type

Tipo dichiarato nel contratto dati.

knownTypeResolver
DataContractResolver

Sistema di risoluzione dei tipi noto.

Valori restituiti

Tipo a cui viene eseguito il mapping del xsi:type nome e dello spazio dei nomi.

Attributi

Esempio

Nell'esempio seguente viene illustrata un'implementazione del ResolveName metodo .

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

Commenti

Se si vuole usare la logica di risoluzione dei tipi nota all'interno dell'implementazione, viene passato un riferimento come knownTypeResolver parametro.

Si applica a