Open sandboxFocus

Method CreateRule

CreateRule<T>(Action<IEligibilityBuilder<T>>, params Action<IEligibilityBuilder<T>>[]?)

Creates a custom instance of the IEligibilityRule<T> interface using a builder pattern.

Declaration
public static IEligibilityRule<T> CreateRule<T>(Action<IEligibilityBuilder<T>> predicate, params Action<IEligibilityBuilder<T>>[]? otherPredicates) where T : class
Parameters
Type Name Description
Action<IEligibilityBuilder<T>> predicate

An action that configures the eligibility builder by adding rules using methods from EligibilityExtensions.

Action<IEligibilityBuilder<T>>[] otherPredicates

Additional actions that configure the eligibility builder. All actions are combined with AND logic.

Returns
Type Description
IEligibilityRule<T>

An immutable IEligibilityRule<T> that can be used to validate declarations.

Type Parameters
Name Description
T

The type of declaration that the rule validates.

Remarks

Eligibility rules are relatively expensive objects to create, although their evaluation is fast and efficient. It is strongly recommended to store rules in static fields of the aspect class to avoid recreating them for each aspect instance.

The created rule can be used with VerifyEligibility(IEligibilityRule<TAspectTarget>) to programmatically validate eligibility within aspect logic.

CreateRule<TGeneral, TRequired>(Action<IEligibilityBuilder<TRequired>>, params Action<IEligibilityBuilder<TRequired>>[]?)

Creates a custom instance of the IEligibilityRule<T> interface that validates a general type but requires a more specific type for the rule definition.

Declaration
public static IEligibilityRule<TGeneral> CreateRule<TGeneral, TRequired>(Action<IEligibilityBuilder<TRequired>> predicate, params Action<IEligibilityBuilder<TRequired>>[]? otherPredicates) where TGeneral : class where TRequired : class, TGeneral
Parameters
Type Name Description
Action<IEligibilityBuilder<TRequired>> predicate

An action that configures the eligibility builder for TRequired by adding rules.

Action<IEligibilityBuilder<TRequired>>[] otherPredicates

Additional actions that configure the eligibility builder. All actions are combined with AND logic.

Returns
Type Description
IEligibilityRule<TGeneral>

An immutable IEligibilityRule<T> for TGeneral that implicitly requires the declaration to be of type TRequired.

Type Parameters
Name Description
TGeneral

The general type of declaration that the rule can validate (e.g., IDeclaration).

TRequired

The more specific type required for building the rule (e.g., IMethod). Must be derived from TGeneral.

Remarks

This overload automatically adds a type conversion requirement (using To<TOutput>()), making declarations ineligible if they are not of type TRequired.

Eligibility rules are relatively expensive objects to create. Store them in static fields to avoid recreating them for each aspect instance.