XmlSchemaClassGenerator
XmlSchemaClassGenerator copied to clipboard
Enum list in attribute
Thanks for a great tool. I'm trying to migrate some code generation from xsd.exe
and found one place where your generator fails
Following schema:
<xs:simpleType name="FontAttributes">
<xs:list>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Bold"/>
<xs:enumeration value="Italic"/>
<xs:enumeration value="Underline"/>
</xs:restriction>
</xs:simpleType>
</xs:list>
</xs:simpleType>
<xs:complexType name="DisplayProperties">
<xs:attribute name="foregroundColor" type="xs:string" use="optional">
</xs:attribute>
<xs:attribute name="backgroundColor" type="xs:string" use="optional">
</xs:attribute>
<xs:attribute name="fontAttributes" type="FontAttributes" use="optional">
</xs:attribute>
</xs:complexType>
XSD correctly generates an enum FontAttributes and use it for (de)serialization of fontAttributes
attribute.
[System.FlagsAttribute()]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="cra.vub/webservices/definitions")]
public enum FontAttributes {
/// <remarks/>
Bold = 1,
/// <remarks/>
Italic = 2,
/// <remarks/>
Underline = 4,
}
But XmlSchemaClassGenerator generates the field as string[] FontAttributes
.
Is my schema wrong or is this problem for XmlSchemaClassGenerator ?
Thanks!
This is currently unsupported. Xsd.exe treats lists of enums as a special case where it generates an enum with FlagsAtribute
and corresponding enum members that are powers of 2. This probably covers the typical use case but doesn't allow for list items to occur more than once.
It would be nice if XmlSchemaClassGenerator had this capability, too (perhaps behind a flag). Would you be interested in providing a PR?
Thanks for confirmation.
Can you label this as enhancement? As I'm pretty busy right now and the workaround is pretty easy, this has no priority. I might take a look at it again in the future (maybe when more people show interest)
Thanks again!