XmlSchemaClassGenerator icon indicating copy to clipboard operation
XmlSchemaClassGenerator copied to clipboard

Duplicate member in code generation

Open thespooler opened this issue 5 years ago • 1 comments

Given the following schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="test" targetNamespace="urn:test" 
    xmlns="urn:test" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="Test">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="Value" type="xs:string" use="required" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:schema>

In the method XmlSchemaClassGenerator.ClassModel.Generate(), the code will go through

    if (BaseClass != null) { 
    ... 
        else if (!string.IsNullOrEmpty(Configuration.TextValuePropertyName)) { ... }
    }

and also in

    foreach (var property in Properties.GroupBy(x => x.Name)) { ... }

generating the following class with the Value attribute appearing twice.

...
    public partial class Test
    {
        [System.Xml.Serialization.XmlTextAttribute()]
        public string Value { get; set; }
        
        [System.Xml.Serialization.XmlAttributeAttribute("Value", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string Value { get; set; }
    }

Command used: XmlSchemaClassGenerator.Console.exe -n "urn:test"=Test Test.xsd

thespooler avatar Feb 11 '20 20:02 thespooler

Does using the --tvpn, --textValuePropertyName command line argument help (e.g. set to TextValue)?

mganss avatar Feb 12 '20 12:02 mganss