SchemaImporterExtension.ImportSchemaType Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Allows you to manipulate the code generated by examining the imported schema and specifying the CLR type that it maps to.
Overloads
ImportSchemaType(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. |
ImportSchemaType(String, String, 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. |
Examples
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;
}
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
ImportSchemaType(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.
public:
virtual System::String ^ ImportSchemaType(System::Xml::Schema::XmlSchemaType ^ type, System::Xml::Schema::XmlSchemaObject ^ context, System::Xml::Serialization::XmlSchemas ^ schemas, System::Xml::Serialization::XmlSchemaImporter ^ importer, System::CodeDom::CodeCompileUnit ^ compileUnit, System::CodeDom::CodeNamespace ^ mainNamespace, System::Xml::Serialization::CodeGenerationOptions options, System::CodeDom::Compiler::CodeDomProvider ^ codeProvider);
public virtual string ImportSchemaType(System.Xml.Schema.XmlSchemaType type, System.Xml.Schema.XmlSchemaObject context, System.Xml.Serialization.XmlSchemas schemas, System.Xml.Serialization.XmlSchemaImporter importer, System.CodeDom.CodeCompileUnit compileUnit, System.CodeDom.CodeNamespace mainNamespace, System.Xml.Serialization.CodeGenerationOptions options, System.CodeDom.Compiler.CodeDomProvider codeProvider);
abstract member ImportSchemaType : System.Xml.Schema.XmlSchemaType * System.Xml.Schema.XmlSchemaObject * System.Xml.Serialization.XmlSchemas * System.Xml.Serialization.XmlSchemaImporter * System.CodeDom.CodeCompileUnit * System.CodeDom.CodeNamespace * System.Xml.Serialization.CodeGenerationOptions * System.CodeDom.Compiler.CodeDomProvider -> string
override this.ImportSchemaType : System.Xml.Schema.XmlSchemaType * System.Xml.Schema.XmlSchemaObject * System.Xml.Serialization.XmlSchemas * System.Xml.Serialization.XmlSchemaImporter * System.CodeDom.CodeCompileUnit * System.CodeDom.CodeNamespace * System.Xml.Serialization.CodeGenerationOptions * System.CodeDom.Compiler.CodeDomProvider -> string
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
Parameters
- type
- XmlSchemaType
The XSD type.
- context
- XmlSchemaObject
The schema information, such as the line number of the XML element.
- schemas
- XmlSchemas
The collection of schemas in the document.
- importer
- XmlSchemaImporter
The importer being used.
- compileUnit
- CodeCompileUnit
A CodeCompileUnit to which you can add CodeDOM structures to generate alternative code for the XSD.
- mainNamespace
- CodeNamespace
The current namespace for the element.
- options
- CodeGenerationOptions
A bitwise combination of the enumeration values that specify the setting options on the code compiler.
- codeProvider
- CodeDomProvider
A CodeDomProvider that is used to generate the new code.
Returns
The name of the CLR type that this maps to.
Examples
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;
}
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
Applies to
.NET Framework 4.8.1 and other versions
Product | Versions |
---|---|
.NET Framework | 2.0, 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 |
ImportSchemaType(String, String, 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.
public:
virtual System::String ^ ImportSchemaType(System::String ^ name, System::String ^ ns, System::Xml::Schema::XmlSchemaObject ^ context, System::Xml::Serialization::XmlSchemas ^ schemas, System::Xml::Serialization::XmlSchemaImporter ^ importer, System::CodeDom::CodeCompileUnit ^ compileUnit, System::CodeDom::CodeNamespace ^ mainNamespace, System::Xml::Serialization::CodeGenerationOptions options, System::CodeDom::Compiler::CodeDomProvider ^ codeProvider);
public virtual string ImportSchemaType(string name, string ns, System.Xml.Schema.XmlSchemaObject context, System.Xml.Serialization.XmlSchemas schemas, System.Xml.Serialization.XmlSchemaImporter importer, System.CodeDom.CodeCompileUnit compileUnit, System.CodeDom.CodeNamespace mainNamespace, System.Xml.Serialization.CodeGenerationOptions options, System.CodeDom.Compiler.CodeDomProvider codeProvider);
abstract member ImportSchemaType : string * string * System.Xml.Schema.XmlSchemaObject * System.Xml.Serialization.XmlSchemas * System.Xml.Serialization.XmlSchemaImporter * System.CodeDom.CodeCompileUnit * System.CodeDom.CodeNamespace * System.Xml.Serialization.CodeGenerationOptions * System.CodeDom.Compiler.CodeDomProvider -> string
override this.ImportSchemaType : string * string * System.Xml.Schema.XmlSchemaObject * System.Xml.Serialization.XmlSchemas * System.Xml.Serialization.XmlSchemaImporter * System.CodeDom.CodeCompileUnit * System.CodeDom.CodeNamespace * System.Xml.Serialization.CodeGenerationOptions * System.CodeDom.Compiler.CodeDomProvider -> string
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
Parameters
- name
- String
The name of the element.
- ns
- String
The namespace of the element.
- context
- XmlSchemaObject
The schema information, such as the line number of the XML element.
- schemas
- XmlSchemas
The collection of schemas in the document.
- importer
- XmlSchemaImporter
The importer being used.
- compileUnit
- CodeCompileUnit
A CodeCompileUnit to which you can add CodeDOM structures to generate alternative code for the XSD.
- mainNamespace
- CodeNamespace
The current namespace for the element.
- options
- CodeGenerationOptions
A bitwise combination of the enumeration values that specify the setting options on the code compiler.
- codeProvider
- CodeDomProvider
A CodeDomProvider that is used to generate the new code.
Returns
The name of the CLR type that this maps to.
Examples
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;
}
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
Remarks
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.
Applies to
.NET Framework 4.8.1 and other versions
Product | Versions |
---|---|
.NET Framework | 2.0, 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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: