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

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out BlockSyntax block))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Simplify lambda expression",
                cancellationToken => SimplifyLambdaExpressionRefactoring.RefactorAsync(context.Document, (LambdaExpressionSyntax)block.Parent, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.SimplifyLambdaExpression));

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

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

            if (block == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Simplify lambda expression",
                cancellationToken => SimplifyLambdaExpressionRefactoring.RefactorAsync(context.Document, (LambdaExpressionSyntax)block.Parent, cancellationToken),
                DiagnosticIdentifiers.SimplifyLambdaExpression + EquivalenceKeySuffix);

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