Table of Contents

Class AsyncPolicyBase<TModel, TMetadata>

Namespace
Motiv
Assembly
Motiv.dll

The base class for asynchronous policies. A policy is a specification that resolves to a single value — one assertion or one metadata object per evaluation. Mirrors PolicyBase<TModel, TMetadata>.

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

Type Parameters

TModel

The model type that the policy will evaluate against

TMetadata

The type of the metadata to associate with the predicate

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

Methods

EvaluateAsync(TModel, CancellationToken)

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

public Task<PolicyResultBase<TMetadata>> EvaluateAsync(TModel model, CancellationToken cancellationToken = default)

Parameters

model TModel

The model to evaluate the policy against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

Task<PolicyResultBase<TMetadata>>

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

EvaluatePolicyAsync(TModel, CancellationToken)

Asynchronously evaluates the policy against the model.

protected abstract Task<PolicyResultBase<TMetadata>> EvaluatePolicyAsync(TModel model, CancellationToken cancellationToken)

Parameters

model TModel

The model to evaluate the policy against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

Task<PolicyResultBase<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 override 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.

Not()

Negates this policy.

public AsyncPolicyBase<TModel, TMetadata> Not()

Returns

AsyncPolicyBase<TModel, TMetadata>

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

OrElse(AsyncPolicyBase<TModel, TMetadata>)

Combines this policy with another policy using the conditional OR operator, preserving the policy guarantee. The right operand is only evaluated if the left operand resolves to false.

public AsyncPolicyBase<TModel, TMetadata> OrElse(AsyncPolicyBase<TModel, TMetadata> alternative)

Parameters

alternative AsyncPolicyBase<TModel, TMetadata>

The fallback policy.

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the conditional OR of this policy and the alternative.

OrElse(PolicyBase<TModel, TMetadata>)

Combines this policy with a synchronous policy using the conditional OR operator, preserving the policy guarantee. The synchronous alternative is lifted into the asynchronous hierarchy via ToAsyncSpec(). The right operand is only evaluated if the left operand resolves to false.

public AsyncPolicyBase<TModel, TMetadata> OrElse(PolicyBase<TModel, TMetadata> alternative)

Parameters

alternative PolicyBase<TModel, TMetadata>

The synchronous fallback policy.

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the conditional OR of this policy and the alternative.

Operators

operator !(AsyncPolicyBase<TModel, TMetadata>)

Negates a policy.

public static AsyncPolicyBase<TModel, TMetadata> operator !(AsyncPolicyBase<TModel, TMetadata> policy)

Parameters

policy AsyncPolicyBase<TModel, TMetadata>

The policy to negate.

Returns

AsyncPolicyBase<TModel, TMetadata>

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