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


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 Overridable Function ImportSchemaType (
	type As XmlSchemaType,
	context As XmlSchemaObject,
	schemas As XmlSchemas,
	importer As XmlSchemaImporter,
	compileUnit As CodeCompileUnit,
	mainNamespace As CodeNamespace,
	options As CodeGenerationOptions,
	codeProvider As CodeDomProvider
) As String


Type: System.Xml.Schema.XmlSchemaType

An XmlSchemaType that represents the XSD type.

Type: System.Xml.Schema.XmlSchemaObject

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

Type: System.Xml.Serialization.XmlSchemas

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

Type: System.Xml.Serialization.XmlSchemaImporter

The XmlSchemaImporter that is the importer being used.

Type: System.CodeDom.CodeCompileUnit

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

Type: System.CodeDom.CodeNamespace

A CodeNamespace that represents the current namespace for the element.

Type: System.Xml.Serialization.CodeGenerationOptions

A CodeGenerationOptions for the setting options on the code compiler.

Type: System.CodeDom.Compiler.CodeDomProvider

A CodeDomProvider that is used to generate the new code.

Return Value

Type: System.String

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 Overrides Function ImportSchemaType(ByVal name As String, ByVal ns As String, ByVal context As XmlSchemaObject, ByVal schemas As XmlSchemas, ByVal importer As XmlSchemaImporter, ByVal compileUnit As CodeCompileUnit, ByVal codeNamespace As CodeNamespace, ByVal options As CodeGenerationOptions, ByVal codeGenerator As CodeDomProvider) As String 
    If name.Equals("Order") AndAlso ns.Equals("http://orders/") Then
        codeNamespace.Imports.Add(New CodeNamespaceImport("Microsoft.Samples"))           
        Return "Order"
    End If 

    Return Nothing

End Function 'ImportSchemaType 

.NET Framework
Available since 2.0
Return to top