Export (0) Print
Expand All

SchemaImporterExtension.ImportSchemaType Method

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

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method 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 method 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.
Top

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;
    }
Show:
© 2014 Microsoft