IDataContractSurrogate.GetReferencedTypeOnImport Method (String, String, Object)


During schema import, returns the type referenced by the schema.

Namespace:   System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

Type GetReferencedTypeOnImport(
	string typeName,
	string typeNamespace,
	object customData


Type: System.String

The name of the type in schema.

Type: System.String

The namespace of the type in schema.

Type: System.Object

The object that represents the annotation inserted into the XML schema definition, which is data that can be used for finding the referenced type.

Return Value

Type: System.Type

The Type to use for the referenced type.

Null should be returned if a CLR type does not exist for representing the schema type. This will cause a new type to be generated during schema import.

The following example shows an implementation of the GetReferencedTypeOnImport method.

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;

.NET Framework
Available since 3.0
Return to top