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

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

            CodeAction codeAction = CodeAction.Create(
                "Call 'ConfigureAwait(false)'",
                cancellationToken => CallConfigureAwaitRefactoring.RefactorAsync(context.Document, awaitExpression, cancellationToken),
                DiagnosticIdentifiers.CallConfigureAwait + EquivalenceKeySuffix);

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

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out AwaitExpressionSyntax awaitExpression))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Call 'ConfigureAwait(false)'",
                cancellationToken => CallConfigureAwaitRefactoring.RefactorAsync(context.Document, awaitExpression, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.CallConfigureAwait));

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