Ejemplo n.º 1
0
        private static ConditionalExpressionSyntax CreateMultilineConditionalExpression(ConditionalExpressionSyntax conditionalExpression)
        {
            SyntaxTriviaList triviaList = SyntaxUtility.GetIndentTrivia(conditionalExpression.Parent).Add(CSharpFactory.IndentTrivia());

            triviaList = triviaList.Insert(0, CSharpFactory.NewLineTrivia());

            ParenthesizedExpressionSyntax condition = null;

            if (conditionalExpression.Condition.IsKind(SyntaxKind.ParenthesizedExpression))
            {
                condition = (ParenthesizedExpressionSyntax)conditionalExpression.Condition;
            }
            else
            {
                condition = ParenthesizedExpression(conditionalExpression.Condition.WithoutTrailingTrivia())
                            .WithCloseParenToken(CreateTokenWithTrailingNewLine(SyntaxKind.CloseParenToken));
            }

            return(ConditionalExpression(
                       condition.WithoutTrailingTrivia(),
                       conditionalExpression.WhenTrue.WithoutTrailingTrivia(),
                       conditionalExpression.WhenFalse.WithoutTrailingTrivia())
                   .WithQuestionToken(CreateToken(SyntaxKind.QuestionToken, triviaList))
                   .WithColonToken(CreateToken(SyntaxKind.ColonToken, triviaList)));
        }