Exemplo n.º 1
0
        public override void Initialize(AnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            base.Initialize(context);

            context.RegisterSyntaxNodeAction(f => RemoveRedundantBaseInterfaceRefactoring.AnalyzeBaseList(f), SyntaxKind.BaseList);
        }
        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);
        }
Exemplo n.º 3
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);
        }