I\'m trying to replace a couple of nodes in a syntax tree using roslyn. But the immutable nature of it seems to get in my way.
public static string Rewrite(s
I guess that the replacement changes the tree so that the other nodes no longer match the original tree and thus cant be replaced.
You're right. Replacing nodes creates entirely new syntax trees. Nodes from previous syntax trees cannot be compared against these new syntax trees.
There are four ways to apply multiple changes to a syntax tree:
Of these options, I believe the DocumentEditor
has the reputation for being the easiest to use. It may very well be the idiomatic way to apply multiple changes going forward.