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

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out SyntaxNode node, predicate: Predicate))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Use expression-bodied member",
                cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, node, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.UseExpressionBodiedMember));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
示例#2
0
        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 <SyntaxNode>(f => Predicate(f));

            Debug.Assert(node != null, "");

            if (node != null)
            {
                CodeAction codeAction = CodeAction.Create(
                    "Use expression-bodied member",
                    cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, node, cancellationToken),
                    DiagnosticIdentifiers.UseExpressionBodiedMember + EquivalenceKeySuffix);

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

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

            if (declaration == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Use expression-bodied member",
                cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, declaration, cancellationToken),
                DiagnosticIdentifiers.UseExpressionBodiedMember + EquivalenceKeySuffix);

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