Class AsyncValueTaskBoxingCodeFixProvider
- Namespace
- CryptoHives.Foundation.Threading.Analyzers
- Assembly
- CryptoHives.Foundation.Threading.Analyzers.dll
Provides code fixes for RedundantAsyncForwarding (CHT011), which removes
the async modifier and returns the awaited ValueTask directly, and for
AsyncWrapperBoxesStateMachine (CHT012), which pools the state machine box.
[ExportCodeFixProvider("C#", new string[] { }, Name = "AsyncValueTaskBoxingCodeFixProvider")]
[Shared]
public sealed class AsyncValueTaskBoxingCodeFixProvider : CodeFixProvider
- Inheritance
-
AsyncValueTaskBoxingCodeFixProvider
- Inherited Members
Remarks
The two fixes differ in how complete they are. CHT011's is exact: the async machinery was buying nothing, and removing it leaves equivalent code.
CHT012's is a mitigation, not a cure. The thorough fix is to relocate the cleanup that forces the await boundary, which is a change to the awaited operation's own design and cannot be derived mechanically. Pooling the box is offered because it is a legitimate one-line improvement that is not widely known - but it only recycles boxes used in sequence and cannot reduce peak live objects, so it helps little when many callers suspend at once. The action title says so, and the fix is only offered when the compilation actually has the pooling builder.
Properties
FixableDiagnosticIds
A list of diagnostic IDs that this provider can provide fixes for.
public override ImmutableArray<string> FixableDiagnosticIds { get; }
Property Value
Methods
GetFixAllProvider()
Gets an optional FixAllProvider that can fix all/multiple occurrences of diagnostics fixed by this code fix provider. Return null if the provider doesn't support fix all/multiple occurrences. Otherwise, you can return any of the well known fix all providers from WellKnownFixAllProviders or implement your own fix all provider.
public override FixAllProvider GetFixAllProvider()
Returns
RegisterCodeFixesAsync(CodeFixContext)
Computes one or more fixes for the specified CodeFixContext.
public override Task RegisterCodeFixesAsync(CodeFixContext context)
Parameters
contextCodeFixContextA CodeFixContext containing context information about the diagnostics to fix. The context must only contain diagnostics with a Id included in the FixableDiagnosticIds for the current provider.