コード例 #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ExpressionSyntax expression)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExtractExpressionFromCondition))
            {
                ExtractExpressionFromIfConditionRefactoring.ComputeRefactoring(context, expression);
                ExtractExpressionFromWhileConditionRefactoring.ComputeRefactoring(context, expression);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ParenthesizeExpression) &&
                context.Span.IsBetweenSpans(expression) &&
                ParenthesizeExpressionRefactoring.CanRefactor(context, expression))
            {
                context.RegisterRefactoring(
                    $"Parenthesize '{expression.ToString()}'",
                    cancellationToken => ParenthesizeExpressionRefactoring.RefactorAsync(context.Document, expression, cancellationToken));
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceNullLiteralExpressionWithDefaultExpression))
            {
                await ReplaceNullLiteralExpressionWithDefaultExpressionRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }

            if (context.Settings.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceConditionalExpressionWithExpression))
            {
                ReplaceConditionalExpressionWithExpressionRefactoring.ComputeRefactoring(context, expression);
            }
        }
コード例 #2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ExpressionSyntax expression)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddBooleanComparison))
            {
                await AddBooleanComparisonRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExtractExpressionFromCondition) &&
                context.Span.IsBetweenSpans(expression))
            {
                ExtractConditionRefactoring.ComputeRefactoring(context, expression);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ParenthesizeExpression) &&
                context.Span.IsBetweenSpans(expression) &&
                ParenthesizeExpressionRefactoring.CanRefactor(context, expression))
            {
                context.RegisterRefactoring(
                    $"Parenthesize '{expression}'",
                    cancellationToken => ParenthesizeExpressionRefactoring.RefactorAsync(context.Document, expression, cancellationToken));
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceNullLiteralExpressionWithDefaultExpression))
            {
                await ReplaceNullLiteralExpressionWithDefaultExpressionRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceConditionalExpressionWithExpression))
            {
                ReplaceConditionalExpressionWithExpressionRefactoring.ComputeRefactoring(context, expression);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckExpressionForNull) &&
                context.Span.IsContainedInSpanOrBetweenSpans(expression))
            {
                await CheckExpressionForNullRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceExpressionWithConstantValue) &&
                context.Span.IsBetweenSpans(expression))
            {
                await ReplaceExpressionWithConstantValueRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }
        }
コード例 #3
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ExpressionSyntax expression)
        {
            if (context.IsRefactoringEnabled(RefactoringDescriptors.ExtractExpressionFromCondition) &&
                context.Span.IsBetweenSpans(expression))
            {
                ExtractConditionRefactoring.ComputeRefactoring(context, expression);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ParenthesizeExpression) &&
                context.Span.IsBetweenSpans(expression) &&
                ParenthesizeExpressionRefactoring.CanRefactor(context, expression))
            {
                context.RegisterRefactoring(
                    $"Parenthesize '{expression}'",
                    ct => ParenthesizeExpressionRefactoring.RefactorAsync(context.Document, expression, ct),
                    RefactoringDescriptors.ParenthesizeExpression);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ReplaceNullLiteralWithDefaultExpression))
            {
                await ReplaceNullLiteralWithDefaultExpressionRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ReplaceConditionalExpressionWithTrueOrFalseBranch))
            {
                ReplaceConditionalExpressionWithTrueOrFalseBranchRefactoring.ComputeRefactoring(context, expression);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.CheckExpressionForNull) &&
                context.Span.IsContainedInSpanOrBetweenSpans(expression))
            {
                await CheckExpressionForNullRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.InlineConstantValue) &&
                context.Span.IsBetweenSpans(expression))
            {
                await InlineConstantValueRefactoring.ComputeRefactoringAsync(context, expression).ConfigureAwait(false);
            }
        }