public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            SyntaxNode node = root
                .FindNode(context.Span, getInnermostNodeForTie: true)?
                .FirstAncestorOrSelf(SyntaxKind.PropertyDeclaration, SyntaxKind.MethodDeclaration);

            if (node == null)
                return;

            CodeAction codeAction = CodeAction.Create(
                "Remove 'sealed' modifier",
                cancellationToken => RemoveModifierRefactoring.RemoveSealedModifierAsync(context.Document, node, cancellationToken),
                DiagnosticIdentifiers.RemoveRedundantSealedModifier + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Exemple #2
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            SyntaxNode declaration = root
                                     .FindNode(context.Span, getInnermostNodeForTie: true)?
                                     .FirstAncestorOrSelf(
                SyntaxKind.ClassDeclaration,
                SyntaxKind.StructDeclaration,
                SyntaxKind.InterfaceDeclaration);

            if (declaration == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove 'partial' modifier",
                cancellationToken => RemoveModifierRefactoring.RemovePartialModifierAsync(context.Document, declaration, cancellationToken),
                DiagnosticIdentifiers.RemovePartialModifierFromTypeWithSinglePart + EquivalenceKeySuffix);

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