Table of Contents

Class PolicyBase<TModel, TMetadata>

Namespace
Motiv
Assembly
Motiv.dll

Represents a "policy" whereby an arbitrary rule causes a single metadata instance to be returned for both the true and false conditions.

public abstract class PolicyBase<TModel, TMetadata> : SpecBase<TModel, TMetadata>

Type Parameters

TModel

The model type that the policy is for.

TMetadata

The metadata type that the policy returns.

Inheritance
SpecBase<TModel>
SpecBase<TModel, TMetadata>
PolicyBase<TModel, TMetadata>
Derived
Inherited Members
Extension Methods

Methods

ChangeModelTo<TDerivedModel>()

Changes the TModel Type of the policy.

public PolicyBase<TDerivedModel, TMetadata> ChangeModelTo<TDerivedModel>() where TDerivedModel : TModel

Returns

PolicyBase<TDerivedModel, TMetadata>

A new policy that represents the same policy but with a different TModel.

Type Parameters

TDerivedModel

The type to change the TModel to. This type must be a subclass of TModel.

ChangeModelTo<TNewModel>(Func<TNewModel, TModel>)

Changes the TModel Type of the policy.

public PolicyBase<TNewModel, TMetadata> ChangeModelTo<TNewModel>(Func<TNewModel, TModel> childModelSelector)

Parameters

childModelSelector Func<TNewModel, TModel>

A function that takes the model and returns the child model to evaluate the specification against.

Returns

PolicyBase<TNewModel, TMetadata>

A new policy that represents the same policy but with a different TModel.

Type Parameters

TNewModel

Evaluate(TModel)

Executes the proposition as a policy and returns a PolicyResultBase<TMetadata> primarily containing a single metadata instance.

public PolicyResultBase<TMetadata> Evaluate(TModel model)

Parameters

model TModel

The model to evaluate

Returns

PolicyResultBase<TMetadata>

A PolicyResultBase<TMetadata> containing the metadata instance and the boolean result.

EvaluatePolicy(TModel)

Executes the proposition as a policy and returns a PolicyResultBase<TMetadata> primarily containing a single metadata instance.

protected abstract PolicyResultBase<TMetadata> EvaluatePolicy(TModel model)

Parameters

model TModel

The model to evaluate

Returns

PolicyResultBase<TMetadata>

A PolicyResultBase<TMetadata> containing the metadata instance and the boolean result.

EvaluateSpec(TModel)

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 BooleanResultBase<TMetadata> EvaluateSpec(TModel model)

Parameters

model TModel

The model to evaluate the specification against.

Returns

BooleanResultBase<TMetadata>

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

IsSatisfiedBy(TModel)

Executes the proposition as a policy and returns a PolicyResultBase<TMetadata> primarily containing a single metadata instance.

[Obsolete("Use Evaluate instead.")]
public PolicyResultBase<TMetadata> IsSatisfiedBy(TModel model)

Parameters

model TModel

The model to evaluate

Returns

PolicyResultBase<TMetadata>

A PolicyResultBase<TMetadata> containing the metadata instance and the boolean result.

Not()

Creates a new policy that is equivalent to a logical "NOT" of the current policy.

public PolicyBase<TModel, TMetadata> Not()

Returns

PolicyBase<TModel, TMetadata>

A new PolicyBase<TModel, TMetadata> that will perform the "Not" operation when evaluated.

OrElse(AsyncPolicyBase<TModel, TMetadata>)

Creates a new asynchronous policy that is equivalent to a conditional "OR" of the current policy and the asynchronous alternative policy, preserving the single-value policy guarantee. This policy is lifted into the asynchronous hierarchy via ToAsyncSpec(). In the event that neither policy is satisfied, the alternative policy's "WhenFalse" metadata is selected as the policy value.

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

Parameters

alternative AsyncPolicyBase<TModel, TMetadata>

The asynchronous policy to evaluate in the event that this policy is unsatisfied

Returns

AsyncPolicyBase<TModel, TMetadata>

A new AsyncPolicyBase<TModel, TMetadata> that will perform the "Else" operation between this and alternative when the policy is eventually evaluated.

OrElse(PolicyBase<TModel, TMetadata>)

Creates a new policy that is equivalent to a conditional "OR" of the current policy and the alternative policy. In the event that neither policy is satisfied, the alternative policy's "WhenFalse" metadata is selected as the policy value.

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

Parameters

alternative PolicyBase<TModel, TMetadata>

The policy to evaluate in the event that this policy is unsatisfied

Returns

PolicyBase<TModel, TMetadata>

A new PolicyBase<TModel, TMetadata> that will perform the "Else" operation between this and alternative when the policy is eventually evaluated.

ToAsyncSpec()

Lifts this synchronous policy into the asynchronous hierarchy, preserving the single-value policy guarantee. Evaluation remains fully synchronous internally.

public AsyncPolicyBase<TModel, TMetadata> ToAsyncSpec()

Returns

AsyncPolicyBase<TModel, TMetadata>

An asynchronous view over this policy.

Operators

operator !(PolicyBase<TModel, TMetadata>)

Creates a new policy that is equivalent to a logical "NOT" of the current policy.

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

Parameters

policy PolicyBase<TModel, TMetadata>

The policy to negate

Returns

PolicyBase<TModel, TMetadata>

A new PolicyBase<TModel, TMetadata> that will perform the "Not" operation when evaluated.