Table of Contents

Class AsyncSpecBase<TModel, TMetadata>

Namespace
Motiv
Assembly
Motiv.dll

The base class for asynchronous specifications that yield metadata. Mirrors SpecBase<TModel, TMetadata> for asynchronous evaluation. Results are the same immutable BooleanResultBase<TMetadata> instances produced by synchronous specifications.

public abstract class AsyncSpecBase<TModel, TMetadata> : AsyncSpecBase<TModel>

Type Parameters

TModel

The model type that the specification will evaluate against

TMetadata

The type of the metadata to associate with the predicate

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

Methods

And(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another asynchronous specification using the logical AND operator. Both operands are evaluated sequentially (left, then right), regardless of the left operand's outcome.

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

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

And(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the logical AND operator. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). Both operands are evaluated sequentially (left, then right), regardless of the left operand's outcome.

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

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

AndAlso(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another asynchronous specification using the conditional AND operator. The right operand is only evaluated if the left operand resolves to true — for asynchronous specifications this means the right operand's work (including any I/O) is never started.

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

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

AndAlso(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the conditional AND operator. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). The right operand is only evaluated if the left operand resolves to true — for asynchronous specifications this means the right operand's work (including any I/O) is never started.

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

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

AndConcurrently(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another asynchronous specification using the logical AND operator, evaluating both operands concurrently. The result is indistinguishable from And(AsyncSpecBase<TModel, TMetadata>) — the reason, assertions, and justification are identical; only the evaluation strategy differs. Only use this when both operands' predicates are safe to execute concurrently (e.g. they do not share a non-thread-safe dependency such as an EF Core DbContext).

public AsyncSpecBase<TModel, TMetadata> AndConcurrently(AsyncSpecBase<TModel, TMetadata> spec)

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

AndConcurrently(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the logical AND operator, evaluating both operands concurrently. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). The result is indistinguishable from And(SpecBase<TModel, TMetadata>) — the reason, assertions, and justification are identical; only the evaluation strategy differs. Only use this when both operands' predicates are safe to execute concurrently (e.g. they do not share a non-thread-safe dependency such as an EF Core DbContext).

public AsyncSpecBase<TModel, TMetadata> AndConcurrently(SpecBase<TModel, TMetadata> spec)

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

A new specification that represents the logical 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 in addition to the metadata.

public Task<BooleanResultBase<TMetadata>> 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<TMetadata>>

A result that contains the Boolean result of the predicate in addition to the metadata.

EvaluateSpecAsync(TModel, CancellationToken)

Asynchronously evaluates the specification against the model and returns a result that contains the Boolean result of the predicate in addition to the metadata.

protected abstract Task<BooleanResultBase<TMetadata>> EvaluateSpecAsync(TModel model, CancellationToken cancellationToken)

Parameters

model TModel

The model to evaluate the specification against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

Task<BooleanResultBase<TMetadata>>

A result that contains the Boolean result of the predicate in addition to the metadata.

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 override 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, TMetadata> Not()

Returns

AsyncSpecBase<TModel, TMetadata>

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

Or(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another specification using the logical OR operator.

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

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

Or(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the logical OR operator. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

OrConcurrently(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another asynchronous specification using the logical OR operator, evaluating both operands concurrently. The result is indistinguishable from Or(AsyncSpecBase<TModel, TMetadata>) — the reason, assertions, and justification are identical; only the evaluation strategy differs. Only use this when both operands' predicates are safe to execute concurrently (e.g. they do not share a non-thread-safe dependency such as an EF Core DbContext).

public AsyncSpecBase<TModel, TMetadata> OrConcurrently(AsyncSpecBase<TModel, TMetadata> spec)

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

OrConcurrently(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the logical OR operator, evaluating both operands concurrently. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). The result is indistinguishable from Or(SpecBase<TModel, TMetadata>) — the reason, assertions, and justification are identical; only the evaluation strategy differs. Only use this when both operands' predicates are safe to execute concurrently (e.g. they do not share a non-thread-safe dependency such as an EF Core DbContext).

public AsyncSpecBase<TModel, TMetadata> OrConcurrently(SpecBase<TModel, TMetadata> spec)

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

OrElse(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another specification using the conditional OR operator. The right operand is only evaluated if the left operand resolves to false, since a true left operand means the OR operation is already satisfied — for asynchronous specifications this means the right operand's work (including any I/O) is never started.

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

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The right operand.

Returns

AsyncSpecBase<TModel, TMetadata>

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

OrElse(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the conditional OR operator. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). The right operand is only evaluated if the left operand resolves to false, since a true left operand means the OR operation is already satisfied — for asynchronous specifications this means the right operand's work (including any I/O) is never started.

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

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous right operand.

Returns

AsyncSpecBase<TModel, TMetadata>

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 override AsyncSpecBase<TModel, string> ToAsyncExplanationSpec()

Returns

AsyncSpecBase<TModel, string>

An equivalent specification that uses assertions as its metadata.

XOr(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another asynchronous specification using the logical XOR operator. Both operands are evaluated sequentially (left, then right), regardless of the outcome.

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

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

XOr(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the logical XOR operator. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). Both operands are evaluated sequentially (left, then right), regardless of the outcome.

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

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

XOrConcurrently(AsyncSpecBase<TModel, TMetadata>)

Combines this specification with another asynchronous specification using the logical XOR operator, evaluating both operands concurrently. The result is indistinguishable from XOr(AsyncSpecBase<TModel, TMetadata>) — the reason, assertions, and justification are identical; only the evaluation strategy differs. Only use this when both operands' predicates are safe to execute concurrently (e.g. they do not share a non-thread-safe dependency such as an EF Core DbContext).

public AsyncSpecBase<TModel, TMetadata> XOrConcurrently(AsyncSpecBase<TModel, TMetadata> spec)

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

XOrConcurrently(SpecBase<TModel, TMetadata>)

Combines this specification with a synchronous specification using the logical XOR operator, evaluating both operands concurrently. The synchronous operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). The result is indistinguishable from XOr(SpecBase<TModel, TMetadata>) — the reason, assertions, and justification are identical; only the evaluation strategy differs. Only use this when both operands' predicates are safe to execute concurrently (e.g. they do not share a non-thread-safe dependency such as an EF Core DbContext).

public AsyncSpecBase<TModel, TMetadata> XOrConcurrently(SpecBase<TModel, TMetadata> spec)

Parameters

spec SpecBase<TModel, TMetadata>

The synchronous specification to combine with this specification.

Returns

AsyncSpecBase<TModel, TMetadata>

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

Operators

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

Combines two asynchronous specifications using the logical AND operator.

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

Parameters

left AsyncSpecBase<TModel, TMetadata>

The left operand of the AND operation.

right AsyncSpecBase<TModel, TMetadata>

The right operand of the AND operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines an asynchronous specification with a synchronous specification using the logical AND operator. The synchronous right operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

left AsyncSpecBase<TModel, TMetadata>

The asynchronous left operand of the AND operation.

right SpecBase<TModel, TMetadata>

The synchronous right operand of the AND operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines a synchronous specification with an asynchronous specification using the logical AND operator. The synchronous left operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

left SpecBase<TModel, TMetadata>

The synchronous left operand of the AND operation.

right AsyncSpecBase<TModel, TMetadata>

The asynchronous right operand of the AND operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines two asynchronous specifications using the logical OR operator.

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

Parameters

left AsyncSpecBase<TModel, TMetadata>

The left operand of the OR operation.

right AsyncSpecBase<TModel, TMetadata>

The right operand of the OR operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines an asynchronous specification with a synchronous specification using the logical OR operator. The synchronous right operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

left AsyncSpecBase<TModel, TMetadata>

The asynchronous left operand of the OR operation.

right SpecBase<TModel, TMetadata>

The synchronous right operand of the OR operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines a synchronous specification with an asynchronous specification using the logical OR operator. The synchronous left operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

left SpecBase<TModel, TMetadata>

The synchronous left operand of the OR operation.

right AsyncSpecBase<TModel, TMetadata>

The asynchronous right operand of the OR operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines two asynchronous specifications using the logical XOR operator.

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

Parameters

left AsyncSpecBase<TModel, TMetadata>

The left operand of the XOR operation.

right AsyncSpecBase<TModel, TMetadata>

The right operand of the XOR operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines an asynchronous specification with a synchronous specification using the logical XOR operator. The synchronous right operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

left AsyncSpecBase<TModel, TMetadata>

The asynchronous left operand of the XOR operation.

right SpecBase<TModel, TMetadata>

The synchronous right operand of the XOR operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

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

Combines a synchronous specification with an asynchronous specification using the logical XOR operator. The synchronous left operand is lifted into the asynchronous hierarchy via ToAsyncSpec().

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

Parameters

left SpecBase<TModel, TMetadata>

The synchronous left operand of the XOR operation.

right AsyncSpecBase<TModel, TMetadata>

The asynchronous right operand of the XOR operation.

Returns

AsyncSpecBase<TModel, TMetadata>

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

operator !(AsyncSpecBase<TModel, TMetadata>)

Negates a specification.

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

Parameters

spec AsyncSpecBase<TModel, TMetadata>

The specification to negate.

Returns

AsyncSpecBase<TModel, TMetadata>

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