namespace Xrinehart.Tools.WebService.SchemaImporter
{
class DataTableSchemaImporterExtension : SchemaImporterExtension
{
// DataTableSchemaImporterExtension is used for WebServices, it is used to recognize the schema for DataTable within wsdl
Hashtable importedTypes = new Hashtable();
public override string ImportSchemaType(string name, string schemaNamespace, XMLSchemaObject context, XMLSchemas schemas, XMLSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider)
{
IList values = schemas.GetSchemas(schemaNamespace);
if (values.Count != 1)
{
return null;
}
XMLSchema schema = values[0] as XMLSchema;
if (schema == null)
return null;
XMLSchemaType type = (XMLSchemaType)schema.SchemaTypes[new XMLQualifiedName(name, schemaNamespace)];
return ImportSchemaType(type, context, schemas, importer, compileUnit, mainNamespace, options, codeProvider);
}
public override string ImportSchemaType(XMLSchemaType type, XMLSchemaObject context, XMLSchemas schemas, XMLSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider)
{
if (type == null)
{
return null;
}
if (importedTypes[type] != null)
{
mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataSet).Namespace));
compileUnit.ReferencedAssemblies.Add("System.Data.dll");
return (string)importedTypes[type];
}
if (!(context is XMLSchemaElement))
return null;