Want more features on Pastebin? Sign Up, it's FREE!
Guest

Dumper.Dump

By: a guest on Sep 9th, 2010  |  syntax: C#  |  size: 0.77 KB  |  views: 114  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data