Metalama 1.0 / / Metalama Documentation / Aspect API / Metalama.​Framework.​Aspects / IAspect­Receiver<TDeclaration> / Add­Aspect

Method AddAspect

AddAspect(Type, Func<TDeclaration, IAspect>)

Adds a aspect to the current set of declarations or throws an exception if the aspect is not eligible for the aspect. This overload is non-generic.

Declaration
void AddAspect(Type aspectType, Func<TDeclaration, IAspect> createAspect)
Parameters
Type Name Description
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.

Func<TDeclaration, IAspect> createAspect

A function that returns the aspect for a given declaration.

AddAspect<TAspect>(Func<TDeclaration, TAspect>)

Adds an aspect to the current set of declarations or throws an exception if the aspect is not eligible for the aspect.

Declaration
void AddAspect<TAspect>(Func<TDeclaration, TAspect> createAspect)
where TAspect : class, IAspect<TDeclaration>
Parameters
Type Name Description
Func<TDeclaration, TAspect> createAspect

A function that returns the aspect for a given declaration.

Type Parameters
Name Description
TAspect

AddAspect<TAspect>()

Adds an aspect to the current set of declarations or throws an exception if the aspect is not eligible for the aspect. This overload creates a new instance of the aspect class for each target declaration.

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