dotnet / dotnet/command-line-api
API proposal: AcceptOnlyFromAmong for enum
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
```patch
namespace System.CommandLine {
public partial class ArgumentValidation {
+ public static Argument AcceptOnlyFromAmong(
+ this Argument argument,
+ params TEnum[] values)
+ where TEnum: struct, System.Enum;
}
public partial class OptionValidation {
+ public static Option AcceptOnlyFromAmong(
+ this Option option,
+ params TEnum[] values)
+ where TEnum: struct, System.Enum;
}
}
```
Same behaviour as in Argument.AcceptOnlyFromAmong(params string[]) and Option.AcceptOnlyFromAmong(params string[]), except:
- These are only applicable for enum types
- The return type is different (but still matches the `this` parameter)
- The `values` parameter is TEnum[] rather than string[], and the method calls ToString or similar on each value (not sure what to do about values composed of multiple bit flags)
- Validation is case-insensitive like the Enum.Parse call in ArgumentConverter (see also )
Inspired by
Contributor guide
Assessment
This issue has not been assessed yet.