IDataContractSurrogate.GetReferencedTypeOnImport Methode

Definitie

Tijdens het importeren van het schema wordt het type geretourneerd waarnaar wordt verwezen door het 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

Parameters

typeName
String

De naam van het type in het schema.

typeNamespace
String

De naamruimte van het type in het schema.

customData
Object

Het object dat de aantekening vertegenwoordigt die is ingevoegd in de DEFINITIE van het XML-schema. Dit zijn gegevens die kunnen worden gebruikt voor het vinden van het type waarnaar wordt verwezen.

Retouren

De Type te gebruiken voor het type waarnaar wordt verwezen.

Voorbeelden

In het volgende voorbeeld ziet u een implementatie van de GetReferencedTypeOnImport methode.

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

Opmerkingen

Null moet worden geretourneerd als er geen CLR-type bestaat voor het weergeven van het schematype. Dit zorgt ervoor dat er een nieuw type wordt gegenereerd tijdens het importeren van het schema.

Van toepassing op