Binds a parameter of an advice method to the instance of the target, that is, the this object of the target method, field or property.
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class ThisAttribute : AdviceParameterAttributeRemarks
When the instance is of a reference type, the parameter cannot be ref, in or out, and its type must be the type of the
instance, a base type of it, an interface it implements, or a type parameter of the advice method.
When the instance is a struct, the parameter can be:
- of a reference type, such as object or an interface: it receives a boxed copy of the instance;
- of the type of the struct or of a type parameter of the advice method: it receives a copy of the instance;
-
reforin, with the type of the struct: it receives the address of the instance, so the changes made through arefparameter are seen by the target. In an async method or an iterator, the instance is the copy held by the state machine.
When the target is static, the parameter receives null, or the default value of its type, unless IsRequired is true.
In OnInstanceConstructedAdvice, the parameter receives the instance that has just been constructed.
Constructors
| Name | Description |
|---|---|
| ThisAttribute() |
Properties
| Name | Description |
|---|---|
| IsRequired | Gets or sets a value indicating whether the target must have an instance. When this property is |