/// <summary> /// Specifies that values must be a string no more than <paramref name="length"/> characters long. /// </summary> /// <param name="builder">The builder.</param> /// <param name="length">The maximum length.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder MaxLength(this IValidationBuilder builder, int length, string errorMessage = null) => builder.Satisfies <MaxLengthAttribute>(errorMessage, length);
/// <summary> /// Specifies that values must match a regular expression. /// </summary> /// <param name="builder">The builder.</param> /// <param name="pattern">The regular expression.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder RegularExpression(this IValidationBuilder builder, string pattern, string errorMessage = null) => builder.Satisfies <RegularExpressionAttribute>(errorMessage, pattern);
/// <summary> /// Specifies that values must be a valid file path or directory, and the file path must not already exist. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder NonExistingFileOrDirectory(this IValidationBuilder builder, string errorMessage = null) => builder.Satisfies <FileOrDirectoryNotExistsAttribute>(errorMessage);
/// <summary> /// Specifies that values must be legal file paths. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder LegalFilePath(this IValidationBuilder builder, string errorMessage = null) => builder.Satisfies <LegalFilePathAttribute>(errorMessage);
/// <summary> /// Specifies that values must be a path to a file that already exists. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder ExistingFile(this IValidationBuilder builder, string errorMessage = null) => builder.Satisfies <FileExistsAttribute>(errorMessage);
/// <summary> /// Specifies that values must be a path to a directory that already exists. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder ExistingDirectory(this IValidationBuilder builder, string errorMessage = null) => builder.Satisfies <DirectoryExistsAttribute>(errorMessage);
/// <summary> /// Specifies that values must be one of the values in a given set. /// </summary> /// <param name="builder">The builder.</param> /// <param name="comparer">The comparer used to determine if values match.</param> /// <param name="allowedValues">Allowed values.</param> /// <returns>The builder.</returns> public static IValidationBuilder Values(this IValidationBuilder builder, StringComparison comparer, params string[] allowedValues) { return(builder.Satisfies <AllowedValuesAttribute>(ctorArgs: new object[] { comparer, allowedValues })); }
/// <summary> /// Specifies that values must be a valid email address. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder EmailAddress(this IValidationBuilder builder, string errorMessage = null) => builder.Satisfies <EmailAddressAttribute>(errorMessage);
/// <summary> /// Specifies that values must match a regular expression. /// </summary> /// <param name="builder">The builder.</param> /// <param name="pattern">The regular expression.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder RegularExpression(this IValidationBuilder builder, string pattern, string?errorMessage = null) => builder.Satisfies(new RegularExpressionAttribute(pattern), errorMessage);
/// <summary> /// Specifies that values must be a string no more than <paramref name="length"/> characters long. /// </summary> /// <param name="builder">The builder.</param> /// <param name="length">The maximum length.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder MaxLength(this IValidationBuilder builder, int length, string?errorMessage = null) => builder.Satisfies(new MaxLengthAttribute(length), errorMessage);
/// <summary> /// Specifies that values must be a valid file path or directory, and the file path must already exist. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder ExistingFileOrDirectory(this IValidationBuilder builder, string?errorMessage = null) => builder.Satisfies(new FileOrDirectoryExistsAttribute(), errorMessage);
/// <summary> /// Specifies that values must be a path to a directory that does not already exist. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorMessage">A custom error message to display.</param> /// <returns>The builder.</returns> public static IValidationBuilder NonExistingDirectory(this IValidationBuilder builder, string?errorMessage = null) => builder.Satisfies(new DirectoryNotExistsAttribute(), errorMessage);
/// <summary> /// Specifies that values must be one of the values in a given set. /// </summary> /// <param name="builder">The builder.</param> /// <param name="comparer">The comparer used to determine if values match.</param> /// <param name="allowedValues">Allowed values.</param> /// <returns>The builder.</returns> public static IValidationBuilder Values(this IValidationBuilder builder, StringComparison comparer, params string[] allowedValues) { return(builder.Satisfies(new AllowedValuesAttribute(comparer, allowedValues))); }