I am writing Roslyn Code Analyzer , which I want to determine if the method asyncdoes not accept CancellationToken, and then suggest a code fix that adds it:
public async Task Example(){}
public async Task Example(CancellationToken token){}
I plugged DiagnosticAnalyzerin to properly report the diagnostics by checking methodDeclaration.ParameterList.Parameters, but I cannot find the Roslyn API to add Paramaterin ParameterListinside a CodeFixProvider.
This is what I have so far:
private async Task<Document> HaveMethodTakeACancellationTokenParameter(
Document document, SyntaxNode syntaxNode, CancellationToken cancellationToken)
{
var method = syntaxNode as MethodDeclarationSyntax;
new ParameterSyntax(typeof(CancellationToken));
}
How to update the method declaration and return the updated one Document?
source
share