Open sandboxFocus

Method RewriteAspectTargetsAsync

RewriteAspectTargetsAsync(CSharpSyntaxRewriter, CancellationToken)

Rewrites only the syntax nodes targeted by aspects, using a thread-safe CSharpSyntaxRewriter.

Declaration
public Task RewriteAspectTargetsAsync(CSharpSyntaxRewriter rewriter, CancellationToken cancellationToken = default)
Parameters
Type Name Description
CSharpSyntaxRewriter rewriter

A thread-safe CSharpSyntaxRewriter whose Visit method is invoked for each declaration that is the target of an aspect in AspectInstances. For partial classes or methods, the Visit method is invoked for each partial declaration separately.

CancellationToken cancellationToken

A CancellationToken to cancel the operation.

Returns
Type Description
Task
Remarks

This method is more efficient than RewriteSyntaxTreesAsync(CSharpSyntaxRewriter, CancellationToken) when you only need to transform declarations that have the aspect applied, because it only visits targeted declarations rather than the entire syntax tree.

The method processes syntax trees in parallel. Your rewriter must be thread-safe.

The Compilation property is automatically updated after the transformation.