Open sandboxFocus

Class MethodAspect

A base class for aspects that target method declarations.

Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[AttributeUsage(AttributeTargets.Method)]
public abstract class MethodAspect : Aspect, IAspect<IMethod>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IMethod>
Remarks

This class provides a convenient base for creating method-level aspects by implementing IAspect<T> with T set to IMethod. Derived classes override BuildAspect(IAspectBuilder<IMethod>) to add advice (such as overriding the method implementation, adding contracts, or introducing attributes) to the target method.

For aspects that specifically override method implementations, consider deriving from OverrideMethodAspect instead, which provides a simpler template-based API.

Aspects can only be applied to run-time code, never to compile-time types or their members. This eligibility restriction is enforced by the BuildEligibility(IEligibilityBuilder<IMethod>) method.

This is a convenience base class. The aspect framework primarily requires implementation of IAspect<T>.

Constructors

Name Description
MethodAspect()

Methods

Name Description
BuildAspect(IAspectBuilder<IMethod>)

Defines the aspect implementation by adding advice, child aspects, and validators to the target declaration.

BuildEligibility(IEligibilityBuilder<IMethod>)

Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to.

Extension Methods

See Also