public static Option ValidateAsEnum(this Option option, Type enumType, bool ignoreCase = true,
                                            int parameterIndex = -1, string message = null)
        {
            EnumValidator validator = CreateValidator(enumType, ignoreCase, message);

            return(option.ValidateWith(parameterIndex, validator).TypedAs(enumType));
        }
        public static Argument ValidateAsEnum(this Argument argument, Type enumType, bool ignoreCase = true,
                                              string message = null)
        {
            EnumValidator validator = CreateValidator(enumType, ignoreCase, message);

            return(argument.ValidateWith(validator));
        }
        public static Argument ValidateAsEnum <TEnum>(this Argument argument, bool ignoreCase = true, string message = null)
            where TEnum : Enum
        {
            var validator = new EnumValidator <TEnum>(ignoreCase);

            if (message != null)
            {
                validator.Message = message;
            }
            return(argument.ValidateWith(validator));
        }
        public static Option ValidateAsEnum <TEnum>(this Option option, bool ignoreCase = true, int parameterIndex = -1,
                                                    string message = null)
            where TEnum : Enum
        {
            var validator = new EnumValidator <TEnum>(ignoreCase);

            if (message != null)
            {
                validator.Message = message;
            }
            return(option.ValidateWith(parameterIndex, validator).TypedAs <TEnum>());
        }
        private static EnumValidator CreateValidator(Type enumType, bool ignoreCase, string message)
        {
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            if (!enumType.IsEnum)
            {
                throw new ArgumentException("Specified type is not an enum.", nameof(enumType));
            }

            var validator = new EnumValidator(enumType, ignoreCase);

            if (message != null)
            {
                validator.Message = message;
            }

            return(validator);
        }