Open sandboxFocus

Interface IAdviceProvider

Interface that allows an aspect to provide advices dynamically, instead of declaratively by using custom attributes.

Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public interface IAdviceProvider : IAspect
Remarks

PostSharp calls ProvideAdvices(object) at build time for each target of the aspect. Implement this interface when the advices depend on the target and cannot be expressed with custom attributes, for example to import several fields or properties of the target class into a single aspect field with ImportLocationAdviceInstance. The other advices that can be provided are ImportMethodAdviceInstance, IntroduceMethodAdviceInstance and IntroduceInterfaceAdviceInstance.

The target element is a System.Reflection object. For C# 14 extension blocks, it represents the code generated by the compiler, so avoid selecting extension block metadata types and their members; use IsExtensionBlockMetadata(MemberInfo) to recognize them.

Methods

Name Description
ProvideAdvices(object)

Provides an enumeration of advices, represented as instances of the AdviceInstance class, for the current aspect instance.

See Also