Open sandboxFocus

Method MustSatisfy

MustSatisfy<T>(IEligibilityBuilder<T>, Predicate<T>, Func<IDescribedObject<T>, FormattableString>)

Adds a custom eligibility condition to the given IEligibilityBuilder, where the condition must be satisfied by the declaration in order to be eligible for the aspect.

Declaration
public static void MustSatisfy<T>(this IEligibilityBuilder<T> eligibilityBuilder, Predicate<T> predicate, Func<IDescribedObject<T>, FormattableString> getJustification) where T : class
Parameters
Type Name Description
IEligibilityBuilder<T> eligibilityBuilder

The parent IEligibilityBuilder.

Predicate<T> predicate

A predicate that returns true if the declaration is eligible for the aspect.

Func<IDescribedObject<T>, FormattableString> getJustification

A delegate called when the predicate returns false and an error message is needed. This delegate must return a FormattableString (a C# interpolated string like $"like {this}") explaining what the declaration must be to satisfy the condition.

Type Parameters
Name Description
T
Remarks

Use this method when standard eligibility methods like MustNotBeStatic(IEligibilityBuilder<IMemberOrNamedType>) or MustNotBeAbstract(IEligibilityBuilder<IMemberOrNamedType>) are insufficient for your requirements. The getJustification message should state what the declaration must be (e.g., "must not be a record type") rather than what it must not be, as this convention combines better when multiple conditions are violated.

Do not format the string yourself—use a raw interpolated string. The framework uses a custom formatter to ensure proper rendering of declarations.