Export (0) Print
Expand All

SchemaImporterExtension.ImportSchemaType Method (XmlSchemaType, XmlSchemaObject, XmlSchemas, XmlSchemaImporter, CodeCompileUnit, CodeNamespace, CodeGenerationOptions, CodeDomProvider)

Note: This method is new in the .NET Framework version 2.0.

Allows you to manipulate the code generated by examining the imported schema and specifying the CLR type that it maps to.

Namespace: System.Xml.Serialization.Advanced
Assembly: System.Xml (in system.xml.dll)

public virtual string ImportSchemaType (
	XmlSchemaType type,
	XmlSchemaObject context,
	XmlSchemas schemas,
	XmlSchemaImporter importer,
	CodeCompileUnit compileUnit,
	CodeNamespace mainNamespace,
	CodeGenerationOptions options,
	CodeDomProvider codeProvider
)
public String ImportSchemaType (
	XmlSchemaType type, 
	XmlSchemaObject context, 
	XmlSchemas schemas, 
	XmlSchemaImporter importer, 
	CodeCompileUnit compileUnit, 
	CodeNamespace mainNamespace, 
	CodeGenerationOptions options, 
	CodeDomProvider codeProvider
)
public function ImportSchemaType (
	type : XmlSchemaType, 
	context : XmlSchemaObject, 
	schemas : XmlSchemas, 
	importer : XmlSchemaImporter, 
	compileUnit : CodeCompileUnit, 
	mainNamespace : CodeNamespace, 
	options : CodeGenerationOptions, 
	codeProvider : CodeDomProvider
) : String

Parameters

type

An XmlSchemaType that represents the XSD type.

context

An XmlSchemaObject that represents schema information, such as the line number of the XML element.

schemas

An XmlSchemas that contains the collection of schemas in the document.

importer

The XmlSchemaImporter that is the importer being used.

compileUnit

A CodeCompileUnit to which you can add CodeDOM structures to generate alternative code for the XSD.

mainNamespace

A CodeNamespace that represents the current namespace for the element.

options

A CodeGenerationOptions for the setting options on the code compiler.

codeProvider

A CodeDomProvider that is used to generate the new code.

Return Value

The name of the CLR type that this maps to.

The example below shows a simple implementation of the ImportSchemaType(String,String,XmlSchemaObject,XmlSchemas,XmlSchemaImporter,CodeCompileUnit,CodeNamespace,CodeGenerationOptions,CodeDomProvider) method. The code checks the namespace and name. When the right values are found, it adds the name of a custom assembly ("Order.dll") that must be referenced in the generated code. It then adds a new namespace ("Microsoft.Samples") that is generated in the code.

public override string ImportSchemaType(string name, string ns, 
    XmlSchemaObject context, XmlSchemas schemas, 
    XmlSchemaImporter importer, 
    CodeCompileUnit compileUnit, CodeNamespace codeNamespace, 
    CodeGenerationOptions options, CodeDomProvider codeGenerator)
    {
        if (name.Equals("Order") && ns.Equals("http://orders/"))
        {
            compileUnit.ReferencedAssemblies.Add("Order.dll");
            codeNamespace.Imports.Add
               (new CodeNamespaceImport("Microsoft.Samples"));
             return "Order";
        }
        return null;
    }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft