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(
                "Remove empty initializer",
                cancellationToken => RemoveEmptyInitializerRefactoring.RefactorAsync(context.Document, objectCreationExpression, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveEmptyInitializer));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Пример #2
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            InitializerExpressionSyntax initializer = root
                                                      .FindNode(context.Span, getInnermostNodeForTie: true)?
                                                      .FirstAncestorOrSelf <InitializerExpressionSyntax>();

            if (initializer == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty initializer",
                cancellationToken => RemoveEmptyInitializerRefactoring.RefactorAsync(context.Document, initializer, cancellationToken),
                DiagnosticIdentifiers.RemoveEmptyInitializer + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }