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 が返ります。 これにより、スキーマのインポート中に新しい型が生成されます。

適用対象