Binds a parameter of an advice method to an argument of the target method, selected by its index, by its name, or by its type.
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class ArgumentAttribute : AdviceParameterAttributeRemarks
The constructor selects the argument:
- ArgumentAttribute(int) selects the argument at a given index.
- ArgumentAttribute(string) selects the argument of a given name.
- ArgumentAttribute() selects the argument whose type can be assigned to the type of the advice parameter without conversion, except boxing. When several arguments match, AmbiguityResolution selects one of them or reports an error.
A parameter without modifier receives the value of the argument. Its type must be the type of the argument, a type to which the argument can be assigned without conversion, except boxing (for instance object), or a type parameter of the advice method. An argument of a value type is boxed when the parameter is of a reference type.
A ref, out or in parameter receives the address of the argument, and its type must be the type of the argument.
Boxing is not supported for such a parameter: when the argument is of a value type and the parameter of a reference type, the compiler
reports an error. The changes made through a ref or out parameter are seen by the target method and by the next advices.
A ref or out parameter cannot be bound to an in argument; use an in parameter.
This attribute can be used in the method boundary advices and in OnMethodInvokeAdvice. It cannot be used in the location interception advices, nor in OnInstanceConstructedAdvice, which runs once the object is constructed, whichever constructor ran. When no argument matches, the compiler reports an error, unless the pointcut skips the targets whose signature does not match, as MatchPointcut does.
Constructors
| Name | Description |
|---|---|
| ArgumentAttribute() | Initializes a new instance of the ArgumentAttribute class that selects the argument whose type can be assigned to the type of the advice parameter. |
| ArgumentAttribute(int) | Initializes a new instance of the ArgumentAttribute class that selects the argument at a given index. |
| ArgumentAttribute(string) | Initializes a new instance of the ArgumentAttribute class that selects the argument of a given name. |
Properties
| Name | Description |
|---|---|
| AmbiguityResolution | Gets or sets the behavior when several arguments match the type of the advice parameter. This property is used only when the argument is selected by its type. The default value is Default, which reports an error. |
| Index | Gets the zero-based index of the argument in the parameter list of the target method, or -1 when the argument is selected by its name or by its type. |
| Name | Gets the name of the parameter of the target method, or |