IDataContractSurrogate.GetReferencedTypeOnImport Method

Definition

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

C#
public Type GetReferencedTypeOnImport(string typeName, string typeNamespace, object customData);

Parameters

typeName
String

The name of the type in schema.

typeNamespace
String

The namespace of the type in schema.

customData
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.

Returns

The Type to use for the referenced type.

Examples

The following example shows an implementation of the GetReferencedTypeOnImport method.

C#
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;
}

Remarks

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.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1