Table of Contents

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

Validator<int>

MoreThanZero

Gets a validator that accepts values greater than zero.

public static Validator<int> MoreThanZero { get; }

Property Value

Validator<int>

NotEmptyString

Gets a validator that rejects null and empty strings.

public static Validator<string> NotEmptyString { get; }

Property Value

Validator<string>

ZeroEqual

Gets a validator that accepts only zero.

public static Validator<int> ZeroEqual { get; }

Property Value

Validator<int>

ZeroNotEqual

Gets a validator that rejects zero.

public static Validator<int> ZeroNotEqual { get; }

Property Value

Validator<int>

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

itemValidator Validator<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

itemValidator Validator<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

validator Validator<int>

Validator applied to collection count.

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

validation Func<T, bool>

Predicate used for validation.

errorMessage string

Error 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

expected T

Expected value.

comparer IEqualityComparer<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

min T

Lower bound.

max T

Upper bound.

rightInclusive bool

true to include the right bound; otherwise it is exclusive.

comparer IComparer<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

Validator<object>

Type validator.

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

value T

Upper inclusive bound.

comparer IComparer<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

value T

Upper exclusive bound.

comparer IComparer<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

pattern string

Regular expression pattern.

options RegexOptions

Regular expression options.

Returns

Validator<string>

Regex validator.

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

value T

Lower inclusive bound.

comparer IComparer<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

value T

Lower exclusive bound.

comparer IComparer<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

expected T

Disallowed value.

comparer IEqualityComparer<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

other Validator<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

min T

Lower bound.

max T

Upper bound.

rightInclusive bool

true to include the right bound; otherwise it is exclusive.

comparer IComparer<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)

Parameters

lengthValidator Validator<int>

Validator applied to string length.

Returns

Validator<string>

String-length validator.