You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a minor issue but it tripped me up for a few minutes. I figured out how to encode flag values in enums when I tried to create a repro in the Fiddle, which was useful to have BTW.
Lets say I have the following flag enum type (simplified from the fiddle site)
In my yaml settings file my first instinct was to encode as I would initialize the enum in C#, with bitwise OR operators indicating which flags were set:
My request is to recognize the | operator as a delimiter as that is how flag values are commonly set in code: var lifeXP = Experiences.TreeChopping | Experiences.CabinLiving;
They are also represented with | delimiters in the Visual Studio debugger.
It is minor but it might save folks a few minutes here and there. Thanks for this useful library.
The text was updated successfully, but these errors were encountered:
To convert it from the value in the YAML file to the enum, Enum.Parse is called which is a core .Net method. Currently we don't do any work on the string or value if the destination type is an enum. I guess we could do some string manipulation to convert pipes to commas for enums, though, not sure we want to do that and it would probably be better to leave it the way it is. Just for completeness, if you do a ToString on a flagged enum it returns commas and not pipes.
I'm going to close this for now, if you feel otherwise reopen and leave a comment.
This is a minor issue but it tripped me up for a few minutes. I figured out how to encode flag values in enums when I tried to create a repro in the Fiddle, which was useful to have BTW.
Lets say I have the following flag enum type (simplified from the fiddle site)
In my yaml settings file my first instinct was to encode as I would initialize the enum in C#, with bitwise OR operators indicating which flags were set:
LifeExperiences: TreeChopping | CabinLiving | BeardGrowing
When that produced a parsing error I tried a list hoping each entry would set the appropriate flag:
Which does not report a parse error. It simply fails to populate the enum (not sure if that behavior would be considered a bug or not).
Finally I noticed the serializer at the top of the Fiddle example and caught on that commas are used for multiple values in a flag enumeration:
LifeExperiences: TreeChopping, CabinLiving, BeardGrowing
My request is to recognize the
|
operator as a delimiter as that is how flag values are commonly set in code:var lifeXP = Experiences.TreeChopping | Experiences.CabinLiving;
They are also represented with
|
delimiters in the Visual Studio debugger.It is minor but it might save folks a few minutes here and there. Thanks for this useful library.
The text was updated successfully, but these errors were encountered: