I am currently working on a three way merge of syntax trees using Roslyn. I have a correspondence between all the children on a ClassDeclerationSyntax node and you want to merge with the children and then create a new tree based on this merge.
O is the input of ClassDeclerationSyntax , and the match has three members (A, O, B) of type MemberDeclerationSyntax .
var updated = O; foreach (var m in matching) { if (mA != null && mB != null && mO != null) { var merge = Merge(mA, mO, mB); var oldUpdated = updated; updated = updated.ReplaceNode(mO, merge); } else if (mA == null && mO == null && mB != null) updated = updated.AddMembers(mB); else if (mA != null && mO == null && mB == null) updated = updated.AddMembers(mA); }
This does not work. At the second iteration, the ReplaceNode returns a completely unmodified node ( oldUpdated == updated is true ).
It seems that after the first iteration of the cycle, all children were restored as new objects, and the original child objects saved in my mapping can no longer be found in the list of children ( updated.ChildNodes().Where(x => x == mO) empty).
What would be a good way to do this?
source share