This documentation is archived and is not being maintained.

IDataContractSurrogate.GetReferencedTypeOnImport Method

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
)

Parameters

typeName
Type: System.String
The name of the type in schema.
typeNamespace
Type: System.String
The namespace of the type in schema.
customData
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

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: