Class Validator
- Namespace
- Executables.Validation
- Assembly
- executables.dll
Factory methods and predefined instances for validators.
public static class Validator
- Inheritance
-
Validator
- Inherited Members
Properties
LessThanZeroOrEqual
Gets a validator that accepts values less than or equal to zero.
public static Validator<int> LessThanZeroOrEqual { get; }
Property Value
MoreThanZero
Gets a validator that accepts values greater than zero.
public static Validator<int> MoreThanZero { get; }
Property Value
NotEmptyString
Gets a validator that rejects null and empty strings.
public static Validator<string> NotEmptyString { get; }
Property Value
ZeroEqual
Gets a validator that accepts only zero.
public static Validator<int> ZeroEqual { get; }
Property Value
ZeroNotEqual
Gets a validator that rejects zero.
public static Validator<int> ZeroNotEqual { get; }
Property Value
Methods
All<T>(Validator<T>)
Creates a validator that requires all sequence items to satisfy the provided validator.
[Pure]
public static Validator<IEnumerable<T>> All<T>(Validator<T> itemValidator)
Parameters
itemValidatorValidator<T>Validator applied to each item.
Returns
- Validator<IEnumerable<T>>
All-items validator.
Type Parameters
T
Any<T>(Validator<T>)
Creates a validator that requires at least one sequence item to satisfy the provided validator.
[Pure]
public static Validator<IEnumerable<T>> Any<T>(Validator<T> itemValidator)
Parameters
itemValidatorValidator<T>Validator applied to each item.
Returns
- Validator<IEnumerable<T>>
Any-item validator.
Type Parameters
T
CollectionCount<T>(Validator<int>)
Creates a validator for collection item count.
[Pure]
public static Validator<ICollection<T>> CollectionCount<T>(Validator<int> validator)
Parameters
Returns
- Validator<ICollection<T>>
Collection-count validator.
Type Parameters
T
Create<T>(Func<T, bool>, string)
Creates a validator from a predicate and an error message.
[Pure]
public static Validator<T> Create<T>(Func<T, bool> validation, string errorMessage)
Parameters
validationFunc<T, bool>Predicate used for validation.
errorMessagestringError message returned on validation failure.
Returns
- Validator<T>
Validator wrapping
validation.
Type Parameters
T
Equal<T>(T, IEqualityComparer<T>)
Creates a validator that checks equality with an expected value.
[Pure]
public static Validator<T> Equal<T>(T expected, IEqualityComparer<T> comparer = null)
Parameters
expectedTExpected value.
comparerIEqualityComparer<T>Optional equality comparer.
Returns
- Validator<T>
Equality validator.
Type Parameters
T
Identity<T>()
Returns a validator that accepts every value.
[Pure]
public static Validator<T> Identity<T>()
Returns
- Validator<T>
Identity validator.
Type Parameters
T
InRange<T>(T, T, bool, IComparer<T>)
Creates a validator that checks whether a value belongs to the specified range.
[Pure]
public static Validator<T> InRange<T>(T min, T max, bool rightInclusive = false, IComparer<T> comparer = null)
Parameters
minTLower bound.
maxTUpper bound.
rightInclusivebooltrue to include the right bound; otherwise it is exclusive.
comparerIComparer<T>Optional comparer.
Returns
- Validator<T>
Range validator.
Type Parameters
T
Is<TExpected>()
Creates a validator that checks whether a value is of the specified runtime type.
[Pure]
public static Validator<object> Is<TExpected>()
Returns
Type Parameters
TExpected
LessThanOrEqual<T>(T, IComparer<T>)
Creates a validator that checks whether a value is less than or equal to the specified value.
[Pure]
public static Validator<T> LessThanOrEqual<T>(T value, IComparer<T> comparer = null)
Parameters
valueTUpper inclusive bound.
comparerIComparer<T>Optional comparer.
Returns
- Validator<T>
Less-than-or-equal validator.
Type Parameters
T
LessThan<T>(T, IComparer<T>)
Creates a validator that checks whether a value is less than the specified value.
[Pure]
public static Validator<T> LessThan<T>(T value, IComparer<T> comparer = null)
Parameters
valueTUpper exclusive bound.
comparerIComparer<T>Optional comparer.
Returns
- Validator<T>
Less-than validator.
Type Parameters
T
Match(string, RegexOptions)
Creates a validator that matches strings against a regular expression.
[Pure]
public static Validator<string> Match(string pattern, RegexOptions options = RegexOptions.None)
Parameters
patternstringRegular expression pattern.
optionsRegexOptionsRegular expression options.
Returns
MoreThanOrEqual<T>(T, IComparer<T>)
Creates a validator that checks whether a value is greater than or equal to the specified value.
[Pure]
public static Validator<T> MoreThanOrEqual<T>(T value, IComparer<T> comparer = null)
Parameters
valueTLower inclusive bound.
comparerIComparer<T>Optional comparer.
Returns
- Validator<T>
Greater-than-or-equal validator.
Type Parameters
T
MoreThan<T>(T, IComparer<T>)
Creates a validator that checks whether a value is greater than the specified value.
[Pure]
public static Validator<T> MoreThan<T>(T value, IComparer<T> comparer = null)
Parameters
valueTLower exclusive bound.
comparerIComparer<T>Optional comparer.
Returns
- Validator<T>
Greater-than validator.
Type Parameters
T
NotEmptyCollection<T>()
Returns a validator that rejects empty collections.
[Pure]
public static Validator<ICollection<T>> NotEmptyCollection<T>()
Returns
- Validator<ICollection<T>>
Not-empty collection validator.
Type Parameters
T
NotEqual<T>(T, IEqualityComparer<T>)
Creates a validator that checks inequality with an expected value.
[Pure]
public static Validator<T> NotEqual<T>(T expected, IEqualityComparer<T> comparer = null)
Parameters
expectedTDisallowed value.
comparerIEqualityComparer<T>Optional equality comparer.
Returns
- Validator<T>
Inequality validator.
Type Parameters
T
NotNull<T>()
Returns a validator that rejects null references.
[Pure]
public static Validator<T> NotNull<T>() where T : class
Returns
- Validator<T>
Not-null validator.
Type Parameters
T
Not<T>(Validator<T>)
Creates a validator that negates another validator.
[Pure]
public static Validator<T> Not<T>(Validator<T> other)
Parameters
otherValidator<T>Validator to negate.
Returns
- Validator<T>
Negated validator.
Type Parameters
T
OutRange<T>(T, T, bool, IComparer<T>)
Creates a validator that checks whether a value lies outside the specified range.
[Pure]
public static Validator<T> OutRange<T>(T min, T max, bool rightInclusive = false, IComparer<T> comparer = null)
Parameters
minTLower bound.
maxTUpper bound.
rightInclusivebooltrue to include the right bound; otherwise it is exclusive.
comparerIComparer<T>Optional comparer.
Returns
- Validator<T>
Out-of-range validator.
Type Parameters
T
StringLength(Validator<int>)
Creates a validator for string length.
[Pure]
public static Validator<string> StringLength(Validator<int> lengthValidator)