BuildEligibility(IEligibilityBuilder<T>)
Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to.
Declaration
[CompileTime]
void BuildEligibility(IEligibilityBuilder<in T> builder)Parameters
| Type | Name | Description |
|---|---|---|
| IEligibilityBuilder<T> | builder | An object that allows defining eligibility rules using methods from EligibilityExtensions, such as MustNotBeStatic(IEligibilityBuilder<IMemberOrNamedType>), MustNotBeAbstract(IEligibilityBuilder<IMemberOrNamedType>), or MustSatisfy<T>(IEligibilityBuilder<T>, Predicate<T>, Func<IDescribedObject<T>, FormattableString>). |
Remarks
Important: Do not reference instance class members in your implementation of BuildEligibility(IEligibilityBuilder<T>). This method is called on an instance obtained using GetUninitializedObject(Type), that is, without invoking the class constructor.
Implementations must call the base class implementation if one exists.
Use MustSatisfy<T>(IEligibilityBuilder<T>, Predicate<T>, Func<IDescribedObject<T>, FormattableString>) to define custom eligibility conditions when standard methods
like MustNotBeStatic or MustNotBeAbstract are insufficient. You can also validate related declarations
such as the declaring type (using DeclaringType<T>(IEligibilityBuilder<T>)), return type
(using ReturnType(IEligibilityBuilder<IMethod>)), or parameters (using Parameter(IEligibilityBuilder<IHasParameters>, int)).
When implementing BuildEligibility(IEligibilityBuilder<T>) manually (instead of inheriting from built-in aspect classes like OverrideMethodAspect or OverrideFieldOrPropertyAspect), you can use GetAdviceEligibilityRule(AdviceKind) to retrieve the default eligibility rules for specific advice kinds and then add only the rules that are specific to your aspect.