IDataContractSurrogate.GetReferencedTypeOnImport Método

Definición

Durante la importación del esquema, devuelve el tipo al que hace referencia el esquema.

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

Parámetros

typeName
String

Nombre del tipo en el esquema.

typeNamespace
String

Espacio de nombres del tipo en el esquema.

customData
Object

Objeto que representa la anotación insertada en la definición de esquema XML, que es datos que se pueden usar para buscar el tipo al que se hace referencia.

Devoluciones

Type que se va a usar para el tipo al que se hace referencia.

Ejemplos

En el ejemplo siguiente se muestra una implementación del GetReferencedTypeOnImport método .

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

Comentarios

Null se debe devolver si no existe un tipo CLR para representar el tipo de esquema. Esto hará que se genere un nuevo tipo durante la importación del esquema.

Se aplica a