XSD exe multiple classes with same name separation

439 views Asked by At

When using XSD.exe to generate classes from XSD files, a certain problem arises for the thing I am trying to do.

I have several (~10) XSD files that are dependent on each other, top-down, with some cross relations as well. These files can be translated into C# files using the XSD.exe tool. Because these are dependent on each other, they should all be generated within one command.

xsd.exe /c xsdfile1.xsd xsdfile2 xsdfile3 xsdfile4 /n:My.csharp.namespace

This command works fine, except for classes that have similar names.
Say there is a class named "User" in xsdfile1.xsd, and there's a class with a similar name "User" in 'xsdfile3.xsd', after the generation, these classes will be named 'User' and 'User1', because there would be a conflict when they would have the same name.

My question is as follows: Is it possible to, instead of adding a number at the end of the class name, separate these classes into multiple namespaces (better multiple files with multiple namespaces), so they can have the same name? Using the xsd.exe tool if possible.

I am unfortunately unable to rename duplicate class names across multiple files since these XSD files are already widely used within the company I am working for.

Example:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="MyObject", Namespace="http://www.example.com/schemas/Extension")]
[System.Xml.Serialization.XmlRootAttribute("myobject", Namespace="http://www.example.com/schemas/Extension", IsNullable=false)]
public partial class MyObject1 : MyObject {
    /// several properties here
}

MyObject1 shouldn't have an added 1 at the end. This could be fixed if the generator did the following:

public partial class MyObject : My.other.namespace.MyObject {
}
0

There are 0 answers