Exemple #1
0
        private void AnalyzeAwaitExpression(SyntaxNodeAnalysisContext context)
        {
            var awaitExpression = (AwaitExpressionSyntax)context.Node;

            if (CallConfigureAwaitRefactoring.CanRefactor(awaitExpression, context.SemanticModel, context.CancellationToken))
            {
                context.ReportDiagnostic(
                    DiagnosticDescriptors.CallConfigureAwait,
                    awaitExpression.Expression);
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
0
        private void AnalyzeAwaitExpression(SyntaxNodeAnalysisContext context)
        {
            if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true)
            {
                return;
            }

            var awaitExpression = (AwaitExpressionSyntax)context.Node;

            if (CallConfigureAwaitRefactoring.CanRefactor(awaitExpression, context.SemanticModel, context.CancellationToken))
            {
                context.ReportDiagnostic(
                    DiagnosticDescriptors.AddConfigureAwait,
                    awaitExpression.Expression.GetLocation());
            }
        }