Binds a parameter of a method boundary advice to the task that the caller of the current async method observes. The parameter is
null until the method has yielded, and always null when the method is not an async method, when it is implemented with
runtime async, or when its method builder is not supported.
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class CurrentTaskAttribute : AdviceParameterAttributeRemarks
The task exists once the method has yielded, that is, once one of its await expressions has suspended it. This applies to every
async method, whether it returns Task, Task<TResult>, ValueTask or ValueTask<TResult>.
The parameter is the task in the resume advice, in a yield advice other than the first one, and in the success, exception and exit advices
of an execution that yielded. It is null in the entry advice, in the first yield advice, and in the advices of an execution that
completes without yielding. Reading the task of the method builder earlier would create a task that the first await replaces on .NET.
The supported method builders are AsyncTaskMethodBuilder, AsyncTaskMethodBuilder<TResult>,
AsyncValueTaskMethodBuilder and AsyncValueTaskMethodBuilder<TResult>. For a method that returns ValueTask or
ValueTask<TResult>, the task is the one that the ValueTask of the caller wraps. Other builders, such as
PoolingAsyncValueTaskMethodBuilder, give null. A method implemented with runtime async has no task while it runs, and the
compiler reports a warning.
The parameter must be of type Task, IAsyncResult or object, and it cannot be ref,
in or out. This attribute can be used only in the method boundary advices.
Constructors
| Name | Description |
|---|---|
| CurrentTaskAttribute() |
Properties
| Name | Description |
|---|---|
| IsRequired | Gets or sets a value indicating whether the parameter must never be |