Exemple #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ArrowExpressionClauseSyntax arrowExpressionClause)
        {
            ExpressionSyntax expression = arrowExpressionClause.Expression;

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CallToMethod))
            {
                await ReturnExpressionRefactoring.ComputeRefactoringsAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandExpressionBody) &&
                (context.Span.IsEmptyAndContainedInSpan(arrowExpressionClause) ||
                 context.Span.IsBetweenSpans(expression)) &&
                ExpandExpressionBodyRefactoring.CanRefactor(arrowExpressionClause))
            {
                context.RegisterRefactoring(
                    "Expand expression body",
                    cancellationToken => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken));
            }
        }
Exemple #2
0
        public static void ComputeRefactorings(RefactoringContext context, SyntaxToken semicolonToken)
        {
            if (!semicolonToken.IsKind(SyntaxKind.SemicolonToken) ||
                semicolonToken.IsMissing)
            {
                return;
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandExpressionBody))
            {
                ArrowExpressionClauseSyntax arrowExpressionClause = GetArrowExpressionClause(semicolonToken);

                if (arrowExpressionClause?.IsMissing == false &&
                    ExpandExpressionBodyRefactoring.CanRefactor(arrowExpressionClause))
                {
                    context.RegisterRefactoring(
                        "Expand expression body",
                        cancellationToken => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken));
                }
            }
        }