Extension methods for IEligibilityBuilder that provide a fluent API for defining aspect eligibility rules.
Namespace: Metalama.Framework.Eligibility
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public static class EligibilityExtensionsRemarks
This class provides the primary API for defining eligibility conditions in the BuildEligibility(IEligibilityBuilder<T>) method. Methods can be categorized into:
- Common rules: Methods like MustNotBeStatic(IEligibilityBuilder<IMemberOrNamedType>), MustNotBeAbstract(IEligibilityBuilder<IMemberOrNamedType>), and MustNotBePartial(IEligibilityBuilder<IMemberOrNamedType>) for standard eligibility conditions.
- Custom rules: MustSatisfy<T>(IEligibilityBuilder<T>, Predicate<T>, Func<IDescribedObject<T>, FormattableString>) for defining custom predicates and error messages.
- Navigation: Methods like DeclaringType<T>(IEligibilityBuilder<T>), ReturnType(IEligibilityBuilder<IMethod>), and Parameter(IEligibilityBuilder<IHasParameters>, int) to validate related declarations.
- Conditional rules: If<T>(IEligibilityBuilder<T>, Predicate<T>) to apply rules conditionally, and MustSatisfyAny<T>(IEligibilityBuilder<T>, params Action<IEligibilityBuilder<T>>[]) for alternative requirements.
- Scenario control: ForScenarios<T>(IEligibilityBuilder<T>, EligibleScenarios) and ExceptForScenarios<T>(IEligibilityBuilder<T>, EligibleScenarios) to restrict eligibility to specific usage scenarios.
Methods
| Name | Description |
|---|---|
| AddRules<T>(IEligibilityBuilder<T>, Action<IEligibilityBuilder<T>>) | Adds rules to the given IEligibilityBuilder by invoking an action that operates directly on the builder. |
| Convert<T>(IEligibilityBuilder<T>) | Gets a converter object that allows transforming the given IEligibilityBuilder into an IEligibilityBuilder for a more specific declaration type. |
| DeclaringMember(IEligibilityBuilder<IParameter>) | Gets an IEligibilityBuilder for the declaring method, property, indexer, or event of the parameter validated by the given IEligibilityBuilder. |
| DeclaringType<T>(IEligibilityBuilder<T>) | Gets an IEligibilityBuilder for the declaring type of the member validated by the given IEligibilityBuilder. |
| ExceptForInheritance<T>(IEligibilityBuilder<T>) | Gets an IEligibilityBuilder for the same declaration as the given IEligibilityBuilder but that is not applicable when the aspect is inheritable and is applied to a declaration that can be inherited or overridden. |
| ExceptForScenarios<T>(IEligibilityBuilder<T>, EligibleScenarios) | Gets an IEligibilityBuilder for the same declaration as the given IEligibilityBuilder but that is not applicable to specified EligibleScenarios. |
| ForScenarios<T>(IEligibilityBuilder<T>, EligibleScenarios) | Gets an IEligibilityBuilder for the same declaration as the given IEligibilityBuilder but that is applicable only to specified EligibleScenarios. |
| If<T>(IEligibilityBuilder<T>, Predicate<T>) | Returns an IEligibilityBuilder that conditionally applies rules based on a predicate. Rules added to the returned builder are only evaluated if the condition is satisfied. |
| IsAdviceEligible(IDeclaration, AdviceKind) | Determines whether the given declaration is an eligible target for a specified kind of advice. |
| IsAspectEligible(IDeclaration, Type, EligibleScenarios) | Determines whether the given declaration is an eligible target for a specified aspect type given as a reflection Type(IEligibilityBuilder<IHasType>). |
| IsAspectEligible<T>(IDeclaration, EligibleScenarios) | Determines whether the given declaration is an eligible target for a specified aspect type given as a type parameter. |
| IsContractAdviceEligible(IDeclaration, ContractDirection) | Determines whether the given declaration is an eligible target for an AddContract advice for a given ContractDirection. |
| MustBe(IEligibilityBuilder<IType>, IType, ConversionKind) | |
| MustBe(IEligibilityBuilder<IType>, Type, ConversionKind) | |
| MustBeConvertibleTo(IEligibilityBuilder<IType>, IType, ConversionKind) | Requires the target type to be convertible to a given type (specified as an IType). |
| MustBeConvertibleTo(IEligibilityBuilder<IType>, Type, ConversionKind) | Requires the target type to be convertible to a given type (specified as a reflection Type). |
| MustBeConvertibleTo<T>(IEligibilityBuilder<IType>, ConversionKind) | Requires the target type to be convertible to a given type (specified as a type parameter). |
| MustBeExplicitlyDeclared(IEligibilityBuilder<IDeclaration>) | Requires the target declaration to be explicitly declared in source code (not compiler-generated). |
| MustBeInstanceOfAnyType<T>(IEligibilityBuilder<T>, params Type[]) | Requires the validated object to be of one of the specified metadata types. Note that this validates the object itself, not the declaration
that it represents. For instance, if the object is an IParameter and the |
| MustBeInstanceOfType<T>(IEligibilityBuilder<T>, Type) | Requires the validated object to be of a certain type of metadata object, e.g. an IField or IMethod.
To check the type of a field, property or parameter, use code like |
| MustBeOfAnyType<T>(IEligibilityBuilder<T>, params Type[]) | |
| MustBeOfType<T>(IEligibilityBuilder<T>, Type) | |
| MustBeReadable(IEligibilityBuilder<IFieldOrPropertyOrIndexer>) | Requires the target field, property, or indexer to be readable. |
| MustBeReadable(IEligibilityBuilder<IParameter>) | Requires the target parameter to be readable, i.e. not |
| MustBeRef(IEligibilityBuilder<IParameter>) | Requires the target parameter to be |
| MustBeReturnParameter(IEligibilityBuilder<IParameter>) | Requires the target parameter to be the return parameter. |
| MustBeRunTimeOnly(IEligibilityBuilder<INamedType>) | Requires the target type to be run-time, as opposed to compile-time or run-time-or-compile-time. |
| MustBeStatic(IEligibilityBuilder<IMemberOrNamedType>) | Requires the target member or type to be static. |
| MustBeWritable(IEligibilityBuilder<IFieldOrPropertyOrIndexer>) | Requires the target field, property, or indexer to be writable. |
| MustBeWritable(IEligibilityBuilder<IParameter>) | Requires the target parameter to be writable, i.e. |
| MustBe<T>(IEligibilityBuilder<IType>, ConversionKind) | |
| MustEqual(IEligibilityBuilder<IType>, SpecialType) | Requires the target type to equal a specified special type. |
| MustEqual(IEligibilityBuilder<IType>, Type) | Requires the target type to equal a specified type (specified as a reflection Type). |
| MustEqual<T>(IEligibilityBuilder<T>, T) | Requires the target declaration to equal a specified value. |
| MustHaveAccessibility(IEligibilityBuilder<IMemberOrNamedType>, Accessibility, params Accessibility[]) | Requires the target member or type to have exactly one of the specified accessibilities. |
| MustHaveAspectOfType(IEligibilityBuilder<IDeclaration>, Type) | Requires the target declaration to have an aspect of a given type. |
| MustHaveAttributeOfType(IEligibilityBuilder<IDeclaration>, Type) | Requires the target declaration to have an attribute of a given type. |
| MustNotBeAbstract(IEligibilityBuilder<IMemberOrNamedType>) | Forbids the target member or type from being abstract. |
| MustNotBeExtensionBlock(IEligibilityBuilder<INamedType>) | Forbids the target type from being an extension block. |
| MustNotBeExtensionBlockReceiverParameter(IEligibilityBuilder<IParameter>) | Forbids the target parameter from being the receiver parameter of an extension block. |
| MustNotBeExtensionMember(IEligibilityBuilder<IMember>) | Forbids the target member from being declared in an extension block. |
| MustNotBeExtern(IEligibilityBuilder<IMethod>) | Forbids the target method from being extern. |
| MustNotBeInterface(IEligibilityBuilder<INamedType>) | Forbids the target type from being an interface. |
| MustNotBePartial(IEligibilityBuilder<IMemberOrNamedType>) | Requires the target declaration not to be partial. |
| MustNotBePartial(IEligibilityBuilder<IMethod>) | Requires the target method not to be partial. |
| MustNotBePrimaryConstructor(IEligibilityBuilder<IConstructor>) | Forbids the target constructor from being a primary constructor. |
| MustNotBePrimaryConstructorOfNonRecordType(IEligibilityBuilder<IConstructor>) | Forbids the target constructor from being a primary constructor of a class or a struct (C# 12.0 feature). |
| MustNotBeRecordCopyConstructor(IEligibilityBuilder<IConstructor>) | Forbids the target constructor from being the copy constructor of a record. |
| MustNotBeRef(IEligibilityBuilder<IFieldOrPropertyOrIndexer>) | Forbids the target field, property, or indexer from being |
| MustNotBeRef(IEligibilityBuilder<IMethod>) | Forbids the target method from returning a |
| MustNotBeRef(IEligibilityBuilder<INamedType>) | Forbids the target type from being a |
| MustNotBeReturnParameter(IEligibilityBuilder<IParameter>) | Forbids the target parameter from being the return parameter. |
| MustNotBeStatic(IEligibilityBuilder<IMemberOrNamedType>) | Forbids the target member or type from being static. |
| MustNotBeVoid(IEligibilityBuilder<IParameter>) | Requires the target parameter not to be |
| MustNotHaveAspectOfType(IEligibilityBuilder<IDeclaration>, Type) | Forbids the target declaration from having an aspect of a given type. |
| MustNotHaveAttributeOfType(IEligibilityBuilder<IDeclaration>, Type) | Forbids the target declaration from having an attribute of a given type. |
| MustNotHaveRefOrOutParameter(IEligibilityBuilder<IMethod>) | Requires the target method not to have |
| MustSatisfyAll<T>(IEligibilityBuilder<T>, params Action<IEligibilityBuilder<T>>[]) | Adds a group of conditions to the given IEligibilityBuilder, where all conditions must be satisfied by the declaration in order to be eligible for the aspect. |
| MustSatisfyAny<T>(IEligibilityBuilder<T>, params Action<IEligibilityBuilder<T>>[]) | Adds a group of conditions to the given IEligibilityBuilder, where at least one condition must be satisfied by the declaration in order to be eligible for the aspect. |
| 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. |
| Parameter(IEligibilityBuilder<IHasParameters>, int) | Gets an IEligibilityBuilder for a parameter of the method, property, indexer, or event validated by the given IEligibilityBuilder, identified by its zero-based index. |
| Parameter(IEligibilityBuilder<IHasParameters>, string) | Gets an IEligibilityBuilder for a parameter of the method, property, indexer, or event validated by the given IEligibilityBuilder, identified by its name. |
| ReturnParameter(IEligibilityBuilder<IMethod>) | Gets an IEligibilityBuilder for the return parameter of the method validated by the given IEligibilityBuilder. |
| ReturnType(IEligibilityBuilder<IMethod>) | Gets an IEligibilityBuilder for the return type of the method validated by the given IEligibilityBuilder. |
| Type(IEligibilityBuilder<IHasType>) | Gets an IEligibilityBuilder for the type of the declaration validated by the given IEligibilityBuilder. |