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

注解

Null 如果不存在用于表示架构类型的 CLR 类型,则应返回该类型。 这将导致在架构导入期间生成新类型。

适用于