Share via


IDataContractSurrogate.GetReferencedTypeOnImport Metodo

Definizione

Durante l'importazione dello schema, restituisce il tipo a cui fa riferimento lo schema.

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

Parametri

typeName
String

Nome del tipo nello schema.

typeNamespace
String

Spazio dei nomi del tipo nello schema.

customData
Object

Oggetto che rappresenta l'annotazione inserita nel documento XSD (XML Schema Definition), ovvero dati che possono essere utilizzati per individuare il tipo a cui viene fatto riferimento.

Restituisce

Tipo Type da utilizzare per il tipo a cui viene fatto riferimento.

Esempio

Nel codice seguente viene illustrata un'implementazione del metodo 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

Commenti

Se non esiste un tipo CLR per la rappresentazione del tipo di schema, deve essere restituito Null. In questo modo durante l'importazione dello schema verrà generato un nuovo tipo.

Si applica a