IDataContractSurrogate.GetReferencedTypeOnImport Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Under schemaimporten returnerar den typ som refereras av schemat.
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
Parametrar
- typeName
- String
Namnet på typen i schemat.
- typeNamespace
- String
Namnområdet för typen i schemat.
- customData
- Object
Objektet som representerar anteckningen som infogats i XML-schemadefinitionen, vilket är data som kan användas för att hitta den refererade typen.
Returer
Att Type använda för den refererade typen.
Exempel
I följande exempel visas en implementering av GetReferencedTypeOnImport metoden.
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
Kommentarer
Null ska returneras om det inte finns någon CLR-typ för att representera schematypen. Detta gör att en ny typ genereras under schemaimporten.