Guest User

Dumper.Dump

a guest
Sep 9th, 2010
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. sealed class Dumper
  2. {
  3.     static public string Dump(Node root)
  4.     {
  5.         StringBuilder builder = new StringBuilder();
  6.         builder.AppendLine(root.Text);
  7.         DumpChildren(builder, "", root);
  8.         return builder.ToString();
  9.     }
  10.     static private void DumpChildren(StringBuilder builder, string prefix, Node node)
  11.     {
  12.         for (int i=0; i != node.Children.Count; ++i)
  13.         {
  14.             Node child = node.Children[i];
  15.             bool isLast = i == node.Children.Count - 1;
  16.             string nodePrefix = prefix + (isLast ? "└─" : "├─");
  17.             string childPrefix = prefix + (isLast ? "  " : "│ ");
  18.             builder.AppendLine(nodePrefix + child.Text);
  19.             DumpChildren(builder, childPrefix, child);
  20.         }
  21.     }
  22. }
Add Comment
Please, Sign In to add comment