DataContractResolver.TryResolveType Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Remplacez cette méthode pour mapper un type de contrat de données à un nom et un xsi:type espace de noms pendant la sérialisation.
public:
abstract bool TryResolveType(Type ^ type, Type ^ declaredType, System::Runtime::Serialization::DataContractResolver ^ knownTypeResolver, [Runtime::InteropServices::Out] System::Xml::XmlDictionaryString ^ % typeName, [Runtime::InteropServices::Out] System::Xml::XmlDictionaryString ^ % typeNamespace);
public abstract bool TryResolveType(Type type, Type declaredType, System.Runtime.Serialization.DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace);
abstract member TryResolveType : Type * Type * System.Runtime.Serialization.DataContractResolver * XmlDictionaryString * XmlDictionaryString -> bool
Public MustOverride Function TryResolveType (type As Type, declaredType As Type, knownTypeResolver As DataContractResolver, ByRef typeName As XmlDictionaryString, ByRef typeNamespace As XmlDictionaryString) As Boolean
Paramètres
- type
- Type
Type à mapper.
- declaredType
- Type
Type déclaré dans le contrat de données.
- knownTypeResolver
- DataContractResolver
Programme de résolution de type connu.
- typeName
- XmlDictionaryString
Nom xsi :type.
- typeNamespace
- XmlDictionaryString
Espace de noms xsi :type.
Retours
true si le mappage a réussi ; sinon, false.
Exemples
L’exemple suivant montre une implémentation de la TryResolveType méthode.
// Used at serialization
// Maps any Type to a new xsi:type representation
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
string name = type.Name;
string namesp = type.Namespace;
typeName = new XmlDictionaryString(XmlDictionary.Empty, name, 0);
typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, namesp, 0);
if (!dictionary.ContainsKey(type.Name))
{
dictionary.Add(name, typeName);
}
if (!dictionary.ContainsKey(type.Namespace))
{
dictionary.Add(namesp, typeNamespace);
}
return true;
}
Remarques
Si vous souhaitez utiliser la logique de résolution de type connue à l’intérieur de votre implémentation, une référence à celle-ci est transmise en tant que knownTypeResolver paramètre.