Table of Contents

Class AsyncSpecBase<TModel>

Namespace
Motiv
Assembly
Motiv.dll

The base class for asynchronous specifications. Mirrors SpecBase<TModel> but evaluates asynchronously via EvaluateAsync(TModel, CancellationToken) and MatchesAsync(TModel, CancellationToken). Async specifications share the non-generic SpecBase root so that names, descriptions, and underlying-spec traversal behave identically to their synchronous counterparts.

public abstract class AsyncSpecBase<TModel> : SpecBase

Type Parameters

TModel

The model type that the specification will evaluate against

Inheritance
AsyncSpecBase<TModel>
Derived
AsyncSpecBase<TModel, TMetadata>
Inherited Members
Extension Methods

Methods

And(AsyncSpecBase<TModel>)

Combines this specification with another asynchronous specification using the logical AND operator. Both operands are lowered to their explanation form via ToAsyncExplanationSpec() so that specifications with differing metadata types can be composed. Both operands will be evaluated, regardless of whether the left operand evaluated to false.

public AsyncSpecBase<TModel, string> And(AsyncSpecBase<TModel> spec)

Parameters

spec AsyncSpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical AND of this specification and the other specification.

And(SpecBase<TModel>)

Combines this specification with a synchronous specification using the logical AND operator. Both operands are lowered to their explanation form; the synchronous operand is then lifted into the asynchronous hierarchy via ToAsyncSpec(). Both operands will be evaluated, regardless of whether the left operand evaluated to false.

public AsyncSpecBase<TModel, string> And(SpecBase<TModel> spec)

Parameters

spec SpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical AND of this specification and the other specification.

AndAlso(AsyncSpecBase<TModel>)

Combines this specification with another asynchronous specification using the conditional AND operator. Both operands are lowered to their explanation form via ToAsyncExplanationSpec() so that specifications with differing metadata types can be composed. The right operand is only evaluated if the left operand evaluates to true. This is commonly referred to as "short-circuiting".

public AsyncSpecBase<TModel, string> AndAlso(AsyncSpecBase<TModel> spec)

Parameters

spec AsyncSpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the conditional AND of this specification and the other specification.

AndAlso(SpecBase<TModel>)

Combines this specification with a synchronous specification using the conditional AND operator. Both operands are lowered to their explanation form; the synchronous operand is then lifted into the asynchronous hierarchy via ToAsyncSpec(). The right operand is only evaluated if the left operand evaluates to true. This is commonly referred to as "short-circuiting".

public AsyncSpecBase<TModel, string> AndAlso(SpecBase<TModel> spec)

Parameters

spec SpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the conditional AND of this specification and the other specification.

EvaluateAsync(TModel, CancellationToken)

Asynchronously evaluates the proposition against the model and returns a result that contains the Boolean result of the predicate and an explanation of the result.

public Task<BooleanResultBase<string>> EvaluateAsync(TModel model, CancellationToken cancellationToken = default)

Parameters

model TModel

The model to evaluate the specification against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

Task<BooleanResultBase<string>>

A result that contains the Boolean result of the predicate and an explanation of the result.

MatchesAsync(TModel, CancellationToken)

Asynchronously evaluates the proposition against the model and returns a boolean indicating whether it is satisfied, without allocating result objects where the underlying propositions permit.

public virtual Task<bool> MatchesAsync(TModel model, CancellationToken cancellationToken = default)

Parameters

model TModel

The model to evaluate the specification against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

Task<bool>

true if the model satisfies the proposition; otherwise, false.

Not()

Negates this specification.

public AsyncSpecBase<TModel, string> Not()

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical NOT of this specification.

Or(AsyncSpecBase<TModel>)

Combines this specification with another asynchronous specification using the logical OR operator. Both operands are lowered to their explanation form via ToAsyncExplanationSpec() so that specifications with differing metadata types can be composed.

public AsyncSpecBase<TModel, string> Or(AsyncSpecBase<TModel> spec)

Parameters

spec AsyncSpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical OR of this specification and the other specification.

Or(SpecBase<TModel>)

Combines this specification with a synchronous specification using the logical OR operator. Both operands are lowered to their explanation form; the synchronous operand is then lifted into the asynchronous hierarchy via ToAsyncSpec().

public AsyncSpecBase<TModel, string> Or(SpecBase<TModel> spec)

Parameters

spec SpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical OR of this specification and the other specification.

OrElse(AsyncSpecBase<TModel>)

Combines this specification with another asynchronous specification using the conditional OR operator. Both operands are lowered to their explanation form via ToAsyncExplanationSpec() so that specifications with differing metadata types can be composed. The right operand is only evaluated if the left operand evaluates to false. This is commonly referred to as "short-circuiting".

public AsyncSpecBase<TModel, string> OrElse(AsyncSpecBase<TModel> spec)

Parameters

spec AsyncSpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the conditional OR of this specification and the other specification.

OrElse(SpecBase<TModel>)

Combines this specification with a synchronous specification using the conditional OR operator. Both operands are lowered to their explanation form; the synchronous operand is then lifted into the asynchronous hierarchy via ToAsyncSpec(). The right operand is only evaluated if the left operand evaluates to false. This is commonly referred to as "short-circuiting".

public AsyncSpecBase<TModel, string> OrElse(SpecBase<TModel> spec)

Parameters

spec SpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the conditional OR of this specification and the other specification.

ToAsyncExplanationSpec()

Converts this specification to an asynchronous explanation specification (i.e., AsyncSpecBase<TModel, string>). This is necessary when establishing a "lowest-common-denominator" between very different specifications.

public abstract AsyncSpecBase<TModel, string> ToAsyncExplanationSpec()

Returns

AsyncSpecBase<TModel, string>

An equivalent specification that uses assertions as its metadata.

ToString()

Serializes the logical hierarchy of the specification to a string.

public override string ToString()

Returns

string

A string that represents the logical hierarchy of the specification.

XOr(AsyncSpecBase<TModel>)

Combines this specification with another asynchronous specification using the logical XOR operator. Both operands are lowered to their explanation form via ToAsyncExplanationSpec() so that specifications with differing metadata types can be composed.

public AsyncSpecBase<TModel, string> XOr(AsyncSpecBase<TModel> spec)

Parameters

spec AsyncSpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical XOR of this specification and the other specification.

XOr(SpecBase<TModel>)

Combines this specification with a synchronous specification using the logical XOR operator. Both operands are lowered to their explanation form; the synchronous operand is then lifted into the asynchronous hierarchy via ToAsyncSpec().

public AsyncSpecBase<TModel, string> XOr(SpecBase<TModel> spec)

Parameters

spec SpecBase<TModel>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical XOR of this specification and the other specification.

Operators

operator &(AsyncSpecBase<TModel>, AsyncSpecBase<TModel>)

Combines two asynchronous specifications using the logical AND operator.

public static AsyncSpecBase<TModel, string> operator &(AsyncSpecBase<TModel> left, AsyncSpecBase<TModel> right)

Parameters

left AsyncSpecBase<TModel>

The left operand of the AND operation.

right AsyncSpecBase<TModel>

The right operand of the AND operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical AND of the two specifications.

operator &(AsyncSpecBase<TModel>, SpecBase<TModel>)

Combines an asynchronous specification with a synchronous specification using the logical AND operator.

public static AsyncSpecBase<TModel, string> operator &(AsyncSpecBase<TModel> left, SpecBase<TModel> right)

Parameters

left AsyncSpecBase<TModel>

The asynchronous left operand of the AND operation.

right SpecBase<TModel>

The synchronous right operand of the AND operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical AND of the two specifications.

operator &(SpecBase<TModel>, AsyncSpecBase<TModel>)

Combines a synchronous specification with an asynchronous specification using the logical AND operator.

public static AsyncSpecBase<TModel, string> operator &(SpecBase<TModel> left, AsyncSpecBase<TModel> right)

Parameters

left SpecBase<TModel>

The synchronous left operand of the AND operation.

right AsyncSpecBase<TModel>

The asynchronous right operand of the AND operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical AND of the two specifications.

operator |(AsyncSpecBase<TModel>, AsyncSpecBase<TModel>)

Combines two asynchronous specifications using the logical OR operator.

public static AsyncSpecBase<TModel, string> operator |(AsyncSpecBase<TModel> left, AsyncSpecBase<TModel> right)

Parameters

left AsyncSpecBase<TModel>

The left operand of the OR operation.

right AsyncSpecBase<TModel>

The right operand of the OR operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical OR of the two specifications.

operator |(AsyncSpecBase<TModel>, SpecBase<TModel>)

Combines an asynchronous specification with a synchronous specification using the logical OR operator.

public static AsyncSpecBase<TModel, string> operator |(AsyncSpecBase<TModel> left, SpecBase<TModel> right)

Parameters

left AsyncSpecBase<TModel>

The asynchronous left operand of the OR operation.

right SpecBase<TModel>

The synchronous right operand of the OR operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical OR of the two specifications.

operator |(SpecBase<TModel>, AsyncSpecBase<TModel>)

Combines a synchronous specification with an asynchronous specification using the logical OR operator.

public static AsyncSpecBase<TModel, string> operator |(SpecBase<TModel> left, AsyncSpecBase<TModel> right)

Parameters

left SpecBase<TModel>

The synchronous left operand of the OR operation.

right AsyncSpecBase<TModel>

The asynchronous right operand of the OR operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical OR of the two specifications.

operator ^(AsyncSpecBase<TModel>, AsyncSpecBase<TModel>)

Combines two asynchronous specifications using the logical XOR operator.

public static AsyncSpecBase<TModel, string> operator ^(AsyncSpecBase<TModel> left, AsyncSpecBase<TModel> right)

Parameters

left AsyncSpecBase<TModel>

The left operand of the XOR operation.

right AsyncSpecBase<TModel>

The right operand of the XOR operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical XOR of the two specifications.

operator ^(AsyncSpecBase<TModel>, SpecBase<TModel>)

Combines an asynchronous specification with a synchronous specification using the logical XOR operator.

public static AsyncSpecBase<TModel, string> operator ^(AsyncSpecBase<TModel> left, SpecBase<TModel> right)

Parameters

left AsyncSpecBase<TModel>

The asynchronous left operand of the XOR operation.

right SpecBase<TModel>

The synchronous right operand of the XOR operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical XOR of the two specifications.

operator ^(SpecBase<TModel>, AsyncSpecBase<TModel>)

Combines a synchronous specification with an asynchronous specification using the logical XOR operator.

public static AsyncSpecBase<TModel, string> operator ^(SpecBase<TModel> left, AsyncSpecBase<TModel> right)

Parameters

left SpecBase<TModel>

The synchronous left operand of the XOR operation.

right AsyncSpecBase<TModel>

The asynchronous right operand of the XOR operation.

Returns

AsyncSpecBase<TModel, string>

A new specification that represents the logical XOR of the two specifications.

operator !(AsyncSpecBase<TModel>)

Negates a specification.

public static AsyncSpecBase<TModel> operator !(AsyncSpecBase<TModel> spec)

Parameters

spec AsyncSpecBase<TModel>

The specification to negate.

Returns

AsyncSpecBase<TModel>

A new specification that represents the logical NOT of the specification.