Open florin141 opened 4 years ago
We have a dictionary of characters that must not occur in an identifier: https://github.com/mganss/XmlSchemaClassGenerator/blob/e0d61196b2293e7ec9b5af30833f4ecf60f0a4a5/XmlSchemaClassGenerator/NamingExtensions.cs#L12-L77
+
is in that dictionary so it gets replaced by Plus
but although -
is also invalid it gets replaced with _
in a separate step. And because _
by itself is again invalid it gets prepended with Item
. The reason we're replacing -
with _
and not Minus
(or Dash
) is that -
occurs frequently as a word separator. I think it might be best to make this a special case so that the exact string "-"
is replaced by "Minus"
.
@florin141 Couldn't you do this by implementing your own NamingProvider?
Mmm, I'm not sure how to do that. But I'll have a closer look at the code soon and I'll try that.
Any idea where I could start?
Make a copy of this: https://github.com/mganss/XmlSchemaClassGenerator/blob/master/XmlSchemaClassGenerator/NamingProvider.cs
Rename it and supply it as NamingProvider.
But you need to generate stuff programatically then (See https://github.com/mganss/XmlSchemaClassGenerator/#usage -> Last part: "For use from code" )
Consider this:
The generated c# code is this:
As you can see, 'Plus' name is a perfect name for the symbol '+', but 'Item_' not so much for the symbol '-'.
Is there any way I could override that behaviour and say something like, for 'SignType' if you encounter an enumeration with value="-", change the name of the property to 'Minus'?