Exemplo n.º 1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, LambdaExpressionSyntax lambda)
        {
            if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertLambdaExpressionBodyToBlockBody) &&
                ConvertLambdaExpressionBodyToBlockBodyRefactoring.CanRefactor(context, lambda))
            {
                context.RegisterRefactoring(
                    "Use block body for lambda expressions",
                    ct =>
                {
                    return(ConvertLambdaExpressionBodyToBlockBodyRefactoring.RefactorAsync(
                               context.Document,
                               lambda,
                               (ExpressionSyntax)lambda.Body,
                               ct));
                },
                    RefactoringDescriptors.ConvertLambdaExpressionBodyToBlockBody);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertLambdaBlockBodyToExpressionBody) &&
                ConvertLambdaExpressionBodyToExpressionBodyAnalysis.IsFixable(lambda))
            {
                context.RegisterRefactoring(
                    ConvertLambdaBlockBodyToExpressionBodyRefactoring.Title,
                    ct =>
                {
                    return(ConvertLambdaBlockBodyToExpressionBodyRefactoring.RefactorAsync(
                               context.Document,
                               lambda,
                               ct));
                },
                    RefactoringDescriptors.ConvertLambdaBlockBodyToExpressionBody);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ExtractEventHandlerMethod) &&
                context.Span.IsBetweenSpans(lambda) &&
                lambda is ParenthesizedLambdaExpressionSyntax parenthesizedLambda)
            {
                await ExtractEventHandlerMethodRefactoring.ComputeRefactoringAsync(context, parenthesizedLambda).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, LambdaExpressionSyntax lambda)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandLambdaExpressionBody) &&
                ExpandLambdaExpressionBodyRefactoring.CanRefactor(context, lambda))
            {
                context.RegisterRefactoring(
                    "Expand lambda expression body",
                    cancellationToken =>
                {
                    return(ExpandLambdaExpressionBodyRefactoring.RefactorAsync(
                               context.Document,
                               lambda,
                               (ExpressionSyntax)lambda.Body,
                               cancellationToken));
                },
                    RefactoringIdentifiers.ExpandLambdaExpressionBody);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.SimplifyLambdaExpression) &&
                SimplifyLambdaExpressionAnalysis.IsFixable(lambda))
            {
                context.RegisterRefactoring(
                    "Simplify lambda expression",
                    cancellationToken =>
                {
                    return(SimplifyLambdaExpressionRefactoring.RefactorAsync(
                               context.Document,
                               lambda,
                               cancellationToken));
                },
                    RefactoringIdentifiers.SimplifyLambdaExpression);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExtractEventHandlerMethod) &&
                context.Span.IsBetweenSpans(lambda) &&
                lambda is ParenthesizedLambdaExpressionSyntax parenthesizedLambda)
            {
                await ExtractEventHandlerMethodRefactoring.ComputeRefactoringAsync(context, parenthesizedLambda).ConfigureAwait(false);
            }
        }