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 не существует для представления типа схемы. Это приведет к созданию нового типа во время импорта схемы.