MetalamaAPI documentationAspect APIMetalama.​Framework.​AspectsIAspect­Receiver<TDeclaration>Add­Aspect­If­Eligible
Open sandboxFocus

Method AddAspectIfEligible

AddAspectIfEligible(Type, Func<TDeclaration, IAspect>, EligibleScenarios)

Adds an aspect to the current set of declarations but only if the aspect is eligible for the declaration. This overload is non-generic.

Declaration
void AddAspectIfEligible(Type aspectType, Func<TDeclaration, IAspect> createAspect, EligibleScenarios eligibility)
Parameters
Type Name Description
System.Type aspectType

The exact type of the aspect returned by createAspect. It is not allowed to specify a base type in this parameter, only the exact type.

System.Func<TDeclaration, IAspect> createAspect

A function that returns the aspect for a given declaration.

EligibleScenarios eligibility

The scenarios for which the aspect may be eligible. The default value is Default | Inheritance. If None is provided, eligibility is not checked.

AddAspectIfEligible<TAspect>(Func<TDeclaration, TAspect>, EligibleScenarios)

Adds an aspect to the current set of declarations but only if the aspect is eligible for the declaration.

Declaration
void AddAspectIfEligible<TAspect>(Func<TDeclaration, TAspect> createAspect, EligibleScenarios eligibility)
where TAspect : class, IAspect<TDeclaration>
Parameters
Type Name Description
System.Func<TDeclaration, TAspect> createAspect

A function that returns the aspect for a given declaration.

EligibleScenarios eligibility

The scenarios for which the aspect may be eligible. The default value is Default | Inheritance. If None is provided, eligibility is not checked.

Type Parameters
Name Description
TAspect

AddAspectIfEligible<TAspect>(EligibleScenarios)

Adds an aspect to the current set of declarations using the default constructor of the aspect type. This method does not verify the eligibility of the declaration for the aspect unless you specify the eligibility parameter. This overload creates a new instance of the aspect class for each eligible target declaration.

Declaration
void AddAspectIfEligible<TAspect>(EligibleScenarios eligibility)
where TAspect : class, IAspect<TDeclaration>, new()
Parameters
Type Name Description
EligibleScenarios eligibility

The scenarios for which the aspect may be eligible. The default value is Default | Inheritance. If None is provided, eligibility is not checked.

Type Parameters
Name Description
TAspect