Binds a parameter of an advice method to the reflection object of the target declaration.
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class DeclarationAttribute : AdviceParameterAttributeRemarks
The value depends on the kind of advice and on the type of the parameter:
- In a method boundary advice and in OnMethodInvokeAdvice, the value is the MethodBase of the
target method. The parameter can be of type MethodBase or of a base type, of type MethodInfo when no target is
a constructor, or of type ConstructorInfo when every target is a constructor. For an async method or an iterator, the value
is the method declared in source code, not the
MoveNextmethod of the state machine. For a generic method or a method of a generic type, the value is the method of the generic instance that is executing. - In a location advice, the value is the LocationInfo of the target field or property when the parameter can receive it, and its PropertyInfo otherwise. The weaver encapsulates an intercepted field into a property, so a field is a property at run time, and a parameter of type FieldInfo is not accepted.
- In OnInstanceConstructedAdvice, the value is the Type of the target type.
The parameter cannot be ref, in or out. A parameter of type MethodInfo on a constructor, or of type
ConstructorInfo on a method, causes an error.
The reflection object is not looked up on each call: it is stored in a static field, except for a generic method or a method of a generic type, which is looked up on each call as Method is.
Constructors
| Name | Description |
|---|---|
| DeclarationAttribute() |