Humanizer
Humanizer copied to clipboard
Humanize(LetterCasing) on enum with Description should leave description string alone
I often do something like enumValue.Humanize(LetterCasing.Title)
, with the intention being that most enum value names can just be translated directly and don't need a description. I do want them to be title cased by default. Sometimes I need to override the default Humanizer behavior to fix casing (like making words "of", "the" lowercase), or making acronyms all uppercase.
With the current implementation, the case is applied even to the string pulled from the Description
attribute, and there doesn't seem to be a way to avoid that. Worse, there doesn't seem to be a way to detect that the string returned by Humanize()
came from an attribute, so I can't selectively apply the case myself.
It seems to me that it would make more sense to only apply the case to descriptions derived from the enum value name, and if the caller wants to apply the case to both, they can easily chain a Transform()
call after Humanize()
.
Since it seems that the entire LetterCasing
API is planned to be deprecated, maybe the correct approach is to have some way of determining if a humanized string was generated from the enum value name or if it came from an attribute.
+1 Having exactly the same frustration for mostly the same reason, though one of my enums includes a company name with stylized capitalization (e.g. "SpaceX"), and the "X" gets lower-cased when calling .Humanize(LetterCasing.Title), despite a Description attribute in place.