An interface that allows aspects to specify to which declarations they can be applied, ensuring predictable behavior and preventing confusing build errors or incorrect code generation patterns.
Namespace: Metalama.Framework.Eligibility
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public interface IEligible<in T> where T : class, IDeclarationType Parameters
| Name | Description |
|---|---|
| T | The type of declaration to which the eligibility applies. |
Remarks
Defining eligibility provides several benefits:
- Predictable behavior: Users receive clear feedback when applying aspects to unsupported declarations.
- Standard error messages: All eligibility errors use consistent, understandable messages.
- IDE support: Only eligible declarations appear in code action and refactoring menus.
Implement the BuildEligibility(IEligibilityBuilder<T>) method to define eligibility rules using the IEligibilityBuilder<T> and extension methods from EligibilityExtensions. Common rules include checking if a method is static, abstract, or has certain parameter types.
Methods
| Name | Description |
|---|---|
| BuildEligibility(IEligibilityBuilder<T>) | Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to. |