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

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out BaseTypeSyntax baseType))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove redundant base interface",
                cancellationToken => RemoveRedundantBaseInterfaceRefactoring.RefactorAsync(context.Document, baseType, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveRedundantBaseInterface));

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

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

            Debug.Assert(baseType != null, $"{nameof(baseType)} is null");

            if (baseType == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove redundant base interface",
                cancellationToken => RemoveRedundantBaseInterfaceRefactoring.RefactorAsync(context.Document, baseType, cancellationToken),
                DiagnosticIdentifiers.RemoveRedundantBaseInterface + EquivalenceKeySuffix);

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