Skip to content

Improve Enum Parsing #326

@jkodroff

Description

@jkodroff

Enum parsing is currently case-sensitive, which makes sense because C# is case-sensitive, but I think we might be able to make the parsing less particular about case and make things a little more intuitive. I'd be willing to do a PR if the powers that be are cool with it. I can think of 2 options off the top of my head:

  1. Allow all lower case values to be parsed.
  2. Allow the user to explicitly specify which parameter values get mapped to which enum members, e.g.
public enum MyEnum 
{
  [ParseArgument("valueone", "VALUEONE")]
  ValueOne
}

While there's nothing stopping someone from defining 2 enum members which only differ by case, it's probably a dumb thing to do so. In either case, it's difficult to 100% guarantee that the parsing will work for all cases b/c of case-sensitivity, but it should improve things for the overwhelming majority of use cases.

Let me know if either of these designs (or a combination of both) are appealing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions