Advertisement
Guest User

Olostan

a guest
Sep 15th, 2010
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. sealed class Dumper
  2. {
  3.   static public string Dump(Node root)
  4.   {
  5.     var sb = new StringBuilder();
  6.     Action<Node, string> action = null;
  7.     action = (node, indent) =>
  8.     {
  9.       // Precondition: indentation and prefix has already been output
  10.       // Precondition: indent is correct for node's *children*
  11.       sb.AppendLine(node.Text);
  12.       for (int i = 0; i < node.Children.Count; ++i)
  13.       {
  14.         bool last = i == node.Children.Count - 1;
  15.         var child = node.Children[i];
  16.         sb.Append(indent);
  17.         sb.Append(last ? '└' : '├');
  18.         sb.Append('─');
  19.         action(child, indent + (last ? "  " : "│ "));
  20.       }
  21.     };
  22.  
  23.     action(root, "");
  24.  
  25.     return sb.ToString();
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement