コード例 #1
0
        private static async Task <Document> ConvertLazyInitializationToCompoundAssignmentAsync(
            Document document,
            BinaryExpressionSyntax coalesceExpression,
            CancellationToken cancellationToken)
        {
            var parenthesizedExpression = (ParenthesizedExpressionSyntax)coalesceExpression.Right;

            var simpleAssignment = (AssignmentExpressionSyntax)parenthesizedExpression.Expression;

            ExpressionSyntax right = simpleAssignment.Right;

            AssignmentExpressionSyntax assignmentExpression = CSharpFactory.CoalesceAssignmentExpression(
                coalesceExpression.Left,
                Token(coalesceExpression.OperatorToken.LeadingTrivia, SyntaxKind.QuestionQuestionEqualsToken, coalesceExpression.OperatorToken.TrailingTrivia),
                right
                .WithoutTrivia()
                .WithTriviaFrom(right)
                .AppendToTrailingTrivia(parenthesizedExpression.GetTrailingTrivia()));

            return(await document.ReplaceNodeAsync(coalesceExpression, assignmentExpression, cancellationToken).ConfigureAwait(false));
        }