XmlSchemaClassGenerator
XmlSchemaClassGenerator copied to clipboard
How to re-map enumerations?
I have the following simpleType which allows for enumeration values as such:
<xs:simpleType name="BaseDates">
<xs:annotation>
<xs:documentation>
Valid base dates that can be used to determine when in a month to disclose
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
<xs:enumeration value="LastDay"/>
<xs:enumeration value="LastDay-1"/>
</xs:restriction>
</xs:simpleType>
These get generated as
public enum BaseDates
{
[System.Xml.Serialization.XmlEnumAttribute("1")]
Item1,
// etc
LastDay,
[System.Xml.Serialization.XmlEnumAttribute("LastDay-1")]
LastDay_1,
//etc
}
I would prefer it to be "Day1", etc, "LastDay", "LastDayMinus1", etc.
There is no mapping mechanism available but you can define your own using the INamingProvider interface.
It would be ideal if we had a general name mapping mechanism using a configuration file which allowed us to use a custom C# name for any name from a schema.