Open
Description
namespace System.CommandLine {
public partial class ArgumentValidation {
+ public static Argument<TEnum> AcceptOnlyFromAmong<TEnum>(
+ this Argument<TEnum> argument,
+ params TEnum[] values)
+ where TEnum: struct, System.Enum;
}
public partial class OptionValidation {
+ public static Option<TEnum> AcceptOnlyFromAmong<TEnum>(
+ this Option<TEnum> 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 Extend
AcceptOnlyFromAmong
withbool ignoreCase = false
#2254)
Inspired by #1959 (comment)