IDataContractSurrogate.GetReferencedTypeOnImport Méthode

Définition

Pendant l'importation de schéma, retourne le type référencé par le schéma.

public:
 Type ^ GetReferencedTypeOnImport(System::String ^ typeName, System::String ^ typeNamespace, System::Object ^ customData);
public Type GetReferencedTypeOnImport (string typeName, string typeNamespace, object customData);
abstract member GetReferencedTypeOnImport : string * string * obj -> Type
Public Function GetReferencedTypeOnImport (typeName As String, typeNamespace As String, customData As Object) As Type

Paramètres

typeName
String

Nom du type dans le schéma.

typeNamespace
String

Espace de noms du type dans le schéma.

customData
Object

L'objet qui représente l'annotation insérée dans la définition de schéma XML, qui correspond à des données qui peuvent être utilisées pour rechercher le type référencé.

Retours

Type

Type à utiliser pour le type référencé.

Exemples

L'exemple suivant illustre une implémentation de la méthode GetReferencedTypeOnImport.

public Type GetReferencedTypeOnImport(string typeName,
    string typeNamespace, object customData)
{
    Console.WriteLine("GetReferencedTypeOnImport invoked");
    // This method is called on schema import.
    // If a PersonSurrogated data contract is
    // in the specified namespace, do not create a new type for it
    // because there is already an existing type, "Person".
    Console.WriteLine( "\t Type Name: {0}", typeName);

    if (typeName.Equals("PersonSurrogated") )
    {
        Console.WriteLine("Returning Person");
        return typeof(Person);
    }
    return null;
}
Public Function GetReferencedTypeOnImport(ByVal typeName As String, _
    ByVal typeNamespace As String, ByVal customData As Object) As Type _
    Implements IDataContractSurrogate.GetReferencedTypeOnImport
    Console.WriteLine("GetReferencedTypeOnImport invoked")
    ' This method is called on schema import.
    ' If a PersonSurrogated data contract is 
    ' in the specified namespace, do not create a new type for it 
    ' because there is already an existing type, "Person".
    Console.WriteLine(vbTab & "Type Name: {0}", typeName)

    'If typeNamespace.Equals("http://schemas.datacontract.org/2004/07/DCSurrogateSample") Then
    If typeName.Equals("PersonSurrogated") Then
        Console.WriteLine("Returning Person")
        Return GetType(Person)
    End If
    'End If
    Return Nothing

End Function

Remarques

Null doit être retourné si un type CLR n'existe pas pour représenter le type de schéma. Cela provoquera la génération d'un nouveau type pendant l'importation de schéma.

S’applique à