public override async Task <Document> RefactorAsync(Document document, CancellationToken cancellationToken = default(CancellationToken)) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); BinaryExpressionSyntax coalesceExpression = RefactoringHelper.CreateCoalesceExpression( semanticModel.GetTypeSymbol(Left, cancellationToken), Right1.WithoutTrivia(), Right2.WithoutTrivia(), IfStatement.SpanStart, semanticModel); ExpressionStatementSyntax newNode = SimpleAssignmentStatement(Left.WithoutTrivia(), coalesceExpression) .WithTriviaFrom(IfStatement) .WithFormatterAnnotation(); return(await document.ReplaceNodeAsync(IfStatement, newNode, cancellationToken).ConfigureAwait(false)); }
public override async Task <Document> RefactorAsync(Document document, CancellationToken cancellationToken = default(CancellationToken)) { ExpressionSyntax left = Right1.WithoutTrivia(); ExpressionSyntax right = Right2.WithoutTrivia(); SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); right = AddCastExpressionIfNecessary(right, semanticModel, IfStatement.SpanStart, cancellationToken); BinaryExpressionSyntax coalesceExpression = CoalesceExpression( left.Parenthesize().WithSimplifierAnnotation(), right.Parenthesize().WithSimplifierAnnotation()); ExpressionStatementSyntax newNode = SimpleAssignmentStatement(Left.WithoutTrivia(), coalesceExpression) .WithTriviaFrom(IfStatement) .WithFormatterAnnotation(); return(await document.ReplaceNodeAsync(IfStatement, newNode, cancellationToken).ConfigureAwait(false)); }