I am using Roslyn CSharpSyntaxRewriter to rewrite the following:
string myString = "Hello "; myString += "World!";
in
string myString = "Hello "; myString += "World!"; Log("myString", myString);
My syntactic rewriter overrides VisitAssignmentExpression as follows.
public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax node) {
I was able to "trick" this restriction when working with StatementSyntax by building BlockSyntax with missing curly braces:
var statements = new SyntaxList<StatementSyntax>();
However, this approach will not work with AssignmentExpressionSyntax , since BlockSyntax cannot be attributed to ExpressionSyntax . ( CSharpSyntaxRewriter is trying to do this. )
How can I rewrite one SyntaxNode to two SyntaxNodes?
Am I facing an API restriction, or are there any tricks like the above that anyone could share?
source share