public async TaskFixAsync(Document document, CodeFixContext context, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken); ... }
public Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var syntaxRoot = await document.GetSyntaxRootAsync(); foreach (var diagnostic in context.Diagnostics) { ... } }Here, the syntax tree root is obtained from the document object and stored in the syntaxRoot variable. It is then used to iterate over all the diagnostics reported by the code analyzer and fix the code accordingly. Package Library: The GetSyntaxRootAsync method is a part of the Microsoft.CodeAnalysis.dll assembly which belongs to the Roslyn API in C#. This library provides advanced tools for refactoring and analyzing C# code.