/// <summary> /// Registers code fix action for the diagnostic /// </summary> /// <param name="context">Code fix context</param> /// <returns>Async Task</returns> public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); foreach (Diagnostic diagnostic in context.Diagnostics) { CodeAction codeAction; switch (diagnostic.Id) { case NoCommentAnalyzer.NoCommentMethodRuleId: { var declaration = AnalyzerUtil.GetDeclaration <BaseMethodDeclarationSyntax>(root, diagnostic); codeAction = CodeAction.Create( title: title, createChangedDocument: c => AddMethodDoxygenCommentAsync(context.Document, declaration, c), equivalenceKey: title); break; } case NoCommentAnalyzer.NoReturnsRuleId: { var declaration = AnalyzerUtil.GetDeclaration <BaseMethodDeclarationSyntax>(root, diagnostic); codeAction = CodeAction.Create( title: title, createChangedDocument: c => AddMethodReturnsCommentAsync(context.Document, declaration, c), equivalenceKey: title); break; } case NoCommentAnalyzer.NoCommentPropertyRuleId: { var declaration = AnalyzerUtil.GetDeclaration <BasePropertyDeclarationSyntax>(root, diagnostic); codeAction = CodeAction.Create( title: title, createChangedDocument: c => AddPropertyDoxygenCommentAsync(context.Document, declaration, c), equivalenceKey: title); break; } case NoCommentAnalyzer.NoSummaryRuleId: { var declaration = AnalyzerUtil.GetDeclaration <BaseTypeDeclarationSyntax>(root, diagnostic); codeAction = CodeAction.Create( title: title, createChangedDocument: c => AddSummaryCommentAsync(context.Document, declaration, c), equivalenceKey: title); break; } case NoCommentAnalyzer.NoCodeRuleId: { var declaration = AnalyzerUtil.GetDeclaration <BaseTypeDeclarationSyntax>(root, diagnostic); codeAction = CodeAction.Create( title: title, createChangedDocument: c => AddCodeCommentAsync(context.Document, declaration, c), equivalenceKey: title); break; } default: { var declaration = AnalyzerUtil.GetDeclaration <BaseTypeDeclarationSyntax>(root, diagnostic); codeAction = CodeAction.Create( title: title, createChangedDocument: c => AddDoxygenCommentAsync(context.Document, declaration, c), equivalenceKey: title); break; } } context.RegisterCodeFix(codeAction, diagnostic); } }