C# Roslyn Deleting/Modifing SyntaxNodes

35 views Asked by At

I am trying to delete spesific nodes from Syntax tree but it throws this exception: System.ArgumentNullException: 'Value cannot be null. Arg_ParamName_Name' (3rd Line in the code)

var syntaxTree = CSharpSyntaxTree.ParseText(textFile);
var root = syntaxTree.GetRoot();
root = root.RemoveNodes(root.DescendantNodes()
.Where(node => node.ChildTokens()
.Any(token => token.ValueText == "Test")), SyntaxRemoveOptions.KeepNoTrivia);

Tried using TrackedNodes but could not get it to work, all the examples seems to be outdated. How should I delete or modify nodes?

0

There are 0 answers