IDataContractSurrogate.GetReferencedTypeOnImport 方法

定義

在結構描述匯入期間,傳回結構描述所參考的型別。

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

參數

typeName
String

在結構描述中的型別名稱。

typeNamespace
String

在結構描述中的型別命名空間。

customData
Object

表示已插入至 XML 結構描述定義中之附註的物件,這個定義是可以用來尋找所參考類型的資料。

傳回

要用在所參考類型的 Type

範例

下列範例會示範 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

備註

如果不存在用來表示結構描述類型的 CLR 類型,就應該傳回 Null。 這將導致在結構描述匯入期間產生新型別。

適用於