using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Xml.Serialization; using System.Xml.Serialization.Advanced; using System.Xml.Schema; using System.CodeDom.Compiler; using System.CodeDom; using System.Collections; namespace SchemasTools.Pocketsoap.Com { public class SfSchemaImporter : SchemaImporterExtension { private Dictionary types = new Dictionary(); public override string ImportSchemaType(string name, string ns, System.Xml.Schema.XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, System.CodeDom.CodeCompileUnit compileUnit, System.CodeDom.CodeNamespace mainNamespace, CodeGenerationOptions options, System.CodeDom.Compiler.CodeDomProvider codeProvider) { XmlQualifiedName qn = new XmlQualifiedName(name, ns); string type; if (types.TryGetValue(qn, out type)) return type; XmlSchemaComplexType ct = (XmlSchemaComplexType)schemas.Find(qn, typeof(XmlSchemaComplexType)); if (ct == null) return null; Console.WriteLine("Generating type {0}", ct.Name); String codeTypeName = codeProvider.CreateValidIdentifier(ct.Name); types[qn] = codeTypeName; CreateComplexType(mainNamespace, codeTypeName, qn, ct); return codeTypeName; } protected void CreateComplexType( CodeNamespace mainNamespace, string codeTypeName, XmlQualifiedName qn, XmlSchemaComplexType ct) { // for now we just create the definition of an empty class CodeTypeDeclaration cls = new CodeTypeDeclaration(codeTypeName); cls.IsClass = true; cls.IsPartial = true; cls.Attributes = MemberAttributes.Public; Console.WriteLine("adding {0} to mainNamespace", codeTypeName); mainNamespace.Types.Add(cls); } } }