Open sandboxFocus

Class AdviceParameterAttribute

Base class of the custom attributes that bind a parameter of an advice method to a value of the target of the advice, such as an argument, the instance, or a variable shared by the advices of a group.

Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
[AttributeUsage(AttributeTargets.Parameter)]
public abstract class AdviceParameterAttribute : Attribute
Remarks

An advice method can receive the values it needs as parameters, instead of a single AdviceArgs object that is allocated on each call. Each parameter must have exactly one advice parameter attribute. Only the first parameter can be passed without attribute, and it must then be of the AdviceArgs type of the advice, for instance MethodExecutionArgs.

The following advices accept bound parameters: the method boundary advices (OnMethodEntryAdvice, OnMethodSuccessAdvice, OnMethodExceptionAdvice, OnMethodExitAdvice, OnMethodYieldAdvice and OnMethodResumeAdvice), OnMethodInvokeAdvice, OnLocationGetValueAdvice, OnLocationSetValueAdvice, and OnInstanceConstructedAdvice, where the target of the bindings is the type: the advice runs once the object is constructed, whichever constructor ran. The other advices, including OnMethodInvokeAsyncAdvice and the event interception advices, do not accept bound parameters.

Each attribute documents the type that the parameter must have, whether the parameter can be ref, in or out, and the advices in which it can be used. The compiler checks these rules when it builds the aspect and when it applies the advice to each target, and it reports an error when a rule is not respected.

The advice method can be generic. The compiler then infers the type arguments of the advice method for each target from the types of the bound values, for instance OnEntry<T>( [Argument( 0 )] T value ).

Only the attributes derived from AdviceParameterAttribute by PostSharp are supported. An attribute derived by the user is reported as an error.

Constructors

Name Description
AdviceParameterAttribute()

Initializes a new instance of the AdviceParameterAttribute class.

See Also