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)
Visual Basic (Declaration)
Public Overridable Function ImportSchemaType ( _
name As String, _
ns As String, _
context As XmlSchemaObject, _
schemas As XmlSchemas, _
importer As XmlSchemaImporter, _
compileUnit As CodeCompileUnit, _
mainNamespace As CodeNamespace, _
options As CodeGenerationOptions, _
codeProvider As CodeDomProvider _
) As String
Dim instance As SchemaImporterExtension
Dim name As String
Dim ns As String
Dim context As XmlSchemaObject
Dim schemas As XmlSchemas
Dim importer As XmlSchemaImporter
Dim compileUnit As CodeCompileUnit
Dim mainNamespace As CodeNamespace
Dim options As CodeGenerationOptions
Dim codeProvider As CodeDomProvider
Dim returnValue As String
returnValue = instance.ImportSchemaType(name, _
ns, context, schemas, importer, compileUnit, _
mainNamespace, options, codeProvider)
public virtual string ImportSchemaType(
string name,
string ns,
XmlSchemaObject context,
XmlSchemas schemas,
XmlSchemaImporter importer,
CodeCompileUnit compileUnit,
CodeNamespace mainNamespace,
CodeGenerationOptions options,
CodeDomProvider codeProvider
)
public:
virtual String^ ImportSchemaType(
String^ name,
String^ ns,
XmlSchemaObject^ context,
XmlSchemas^ schemas,
XmlSchemaImporter^ importer,
CodeCompileUnit^ compileUnit,
CodeNamespace^ mainNamespace,
CodeGenerationOptions options,
CodeDomProvider^ codeProvider
)
public function ImportSchemaType(
name : String,
ns : String,
context : XmlSchemaObject,
schemas : XmlSchemas,
importer : XmlSchemaImporter,
compileUnit : CodeCompileUnit,
mainNamespace : CodeNamespace,
options : CodeGenerationOptions,
codeProvider : CodeDomProvider
) : String
In order to control the generation of the code, you must use the classes found in the System.CodeDom namespace. For more information, see Using the CodeDOM and CodeDOM Quick Reference.
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
compileUnit.ReferencedAssemblies.Add("Order.dll")
codeNamespace.Imports.Add(New CodeNamespaceImport("Microsoft.Samples"))
Return "Order"
End If
Return Nothing
End Function 'ImportSchemaType
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference