static void CSharpSyntaxRewriterDemo3() { var tree = CS.CSharpSyntaxTree.ParseText(@" class Program { static void Main() { if (true) Console.WriteLine(""It was true!""); if (false) Console.WriteLine(""OMG Why not?""); } } "); var root = tree.GetRoot(); DisplayHeader("Root Node"); Console.WriteLine(root.ToFullString()); var rewriter = new VNC.CodeAnalysis.SyntaxRewriters.CS.MyRewriter(); // The CSharpSyntaxRewriter does a depth first pass // it builds trees up from the bottom and glues them together // and covers both if statements var newRoot = rewriter.Visit(root); DisplayHeader("Rewritten Root Node"); Console.WriteLine(newRoot.ToFullString()); }
static void CSharpSyntaxRewriterDemo1() { var tree = CS.CSharpSyntaxTree.ParseText(@" class Program { static void Main() { if (true) Console.WriteLine(""It was true!""); } } "); var root = tree.GetRoot(); DisplayHeader("Root Node"); Console.WriteLine(root.ToFullString()); var rewriter = new VNC.CodeAnalysis.SyntaxRewriters.CS.MyRewriter(); // Pass in node you want to visit. We will start with root. var newRoot = rewriter.Visit(root); DisplayHeader("Rewritten Root Node"); Console.WriteLine(newRoot.ToFullString()); }