MetalamaConceptual documentationCreating aspectsAdding child aspects
Open sandboxFocusImprove this doc

Adding child aspects

An aspect can introduce other aspects to child declarations. These aspects are known as child aspects. Child aspects must adhere to two conditions:

  • The child aspect class should be processed after the parent aspect class. In other words, the child aspect class must be listed before the parent class in the AspectOrderAttribute ordering definition. Please refer to Ordering aspects for more details.
  • The target declaration of the child aspect class must be included in the target type of the parent aspect. For example, a type-level aspect can introduce aspects to methods of the current type, but not to methods of a different type. A parameter-level aspect can add a child aspect to the parent method or another method of the same type, but not of a different type.

An aspect can add child aspects from the BuildAspect method by using the builder.Outbound property, followed by calling the AddAspect method. To introduce child aspects on members of the current declaration, use the Select or SelectMany method, and then invoke AddAspect.

Accessing the parent aspect

Parent aspects are enumerated in the IAspectPredecessor.Predecessors property. The child aspect can access this from meta.AspectInstance or builder.AspectInstance.