public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out ObjectCreationExpressionSyntax objectCreationExpression)) { return; } Document document = context.Document; Diagnostic diagnostic = context.Diagnostics[0]; if (objectCreationExpression.ArgumentList != null) { CodeAction codeAction = CodeAction.Create( "Remove argument list", cancellationToken => RemoveArgumentListFromObjectCreationAsync(document, objectCreationExpression.ArgumentList, cancellationToken), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); } else { CodeAction codeAction = CodeAction.Create( "Add argument list", cancellationToken => AddArgumentListToObjectCreationRefactoring.RefactorAsync(document, objectCreationExpression, cancellationToken), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out ObjectCreationExpressionSyntax objectCreationExpression)) { return; } CodeAction codeAction = CodeAction.Create( "Add parentheses", cancellationToken => AddArgumentListToObjectCreationRefactoring.RefactorAsync(context.Document, objectCreationExpression, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.AddArgumentListToObjectCreation)); context.RegisterCodeFix(codeAction, context.Diagnostics); }