private void RemoveTypes(XmlSchemas schemas, CodeNamespace ns) { CodeTypeDeclaration typeToRemove; foreach (XmlSchema schema in schemas) { foreach (XmlSchemaElement element in schema.Elements.Values) { typeToRemove = CodeCompileUnitHelper.FindTypeDeclarationByName(ns, element.Name); if (typeToRemove != null) { ns.Types.Remove(typeToRemove); } } foreach (XmlSchemaType schemaType in schema.SchemaTypes.Values) { typeToRemove = CodeCompileUnitHelper.FindTypeDeclarationByName(ns, schemaType.Name); if (typeToRemove != null) { ns.Types.Remove(typeToRemove); } } } }
private void GenerateFiles(XmlSchemas schemas) { CodeCompileUnit codeCompileUnit = ExportCodeFromSchemas(schemas); CodeNamespace codeNamespace = codeCompileUnit.Namespaces[0]; CodeDomProvider provider = new CSharpCodeProvider(); CodeGeneratorOptions options = new CodeGeneratorOptions(); foreach (XmlSchema schema in schemas) { CodeCompileUnit codeCompileUnitTemp = new CodeCompileUnit(); codeCompileUnitTemp.Namespaces.Add(new CodeNamespace(this.TargetNamespace)); CodeNamespace codeNamespaceTemp = codeCompileUnitTemp.Namespaces[0]; CodeTypeDeclaration typeToAdd; string fileFullName; foreach (XmlSchemaType schemaType in schema.SchemaTypes.Values) { typeToAdd = CodeCompileUnitHelper.FindTypeDeclarationByName( codeNamespace, schemaType.Name); if (typeToAdd != null && !codeNamespaceTemp.Types.Contains(typeToAdd)) { codeNamespaceTemp.Types.Add(typeToAdd); } } if (!this.ProcessComplexTypesOnly) { foreach (XmlSchemaElement element in schema.Elements.Values) { typeToAdd = CodeCompileUnitHelper.FindTypeDeclarationByName( codeNamespace, element.Name); if (typeToAdd != null && !codeNamespaceTemp.Types.Contains(typeToAdd)) { codeNamespaceTemp.Types.Add(typeToAdd); } } } fileFullName = Path.Combine(this.OutputPath, string.Concat( schema.Id, ".", this.Language)); using (StringWriter sw = new StringWriter()) { provider.GenerateCodeFromNamespace(codeCompileUnitTemp.Namespaces[0], sw, options); System.IO.File.WriteAllText(fileFullName, sw.ToString()); } } }