/// <summary> /// Specifies that values must be one of the values in a given set. /// </summary> /// <param name="builder">The builder.</param> /// <param name="ignoreCase">Ignore case when comparing inputs to <paramref name="allowedValues"/>.</param> /// <param name="allowedValues">Allowed values.</param> /// <returns>The builder.</returns> public static IValidationBuilder Values(this IValidationBuilder builder, bool ignoreCase, params string[] allowedValues) { var comparer = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture; return(builder.Values(comparer, allowedValues)); }
/// <summary> /// <para> /// Specifies that values must be one of the values in a given set. /// </para> /// <para> /// By default, value comparison is case-sensitive. To make matches case-insensitive, set <paramref name="ignoreCase"/> to <c>true</c>. /// </para> /// </summary> /// <param name="builder">The builder.</param> /// <param name="ignoreCase">Ignore case when parsing enums.</param> /// <exception cref="ArgumentException">When <typeparamref name="TEnum"/> is not an enum.</exception> /// <returns>The builder.</returns> public static IValidationBuilder Enum <TEnum>(this IValidationBuilder builder, bool ignoreCase = false) where TEnum : struct { if (!typeof(TEnum).GetTypeInfo().IsEnum) { throw new ArgumentException("Type parameter T must be an enum."); } var comparer = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; return(builder.Values(comparer, System.Enum.GetNames(typeof(TEnum)))); }
/// <summary> /// <para> /// Specifies that values must be one of the values in a given set. /// </para> /// <para> /// By default, value comparison is case-sensitive. To make matches case-insensitive, use <see cref="Values(IValidationBuilder, bool, string[])"/>. /// </para> /// </summary> /// <param name="builder">The builder.</param> /// <param name="allowedValues">Allowed values.</param> /// <returns>The builder.</returns> public static IValidationBuilder Values(this IValidationBuilder builder, params string[] allowedValues) => builder.Values(ignoreCase: false, allowedValues: allowedValues);