This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 10th, 2010  |  syntax: C#  |  size: 1.01 KB  |  views: 149  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     static class Dumper
  2.     {
  3.         public static string Dump(Node root)
  4.         {
  5.             var sb = new StringBuilder();
  6.             foreach (var line in dump(root))
  7.                 sb.AppendLine(line);
  8.             return sb.ToString();
  9.         }
  10.  
  11.         static private IEnumerable<string> dump(Node root)
  12.         {
  13.             yield return root.Text;
  14.             if (root.Children.Count == 0)
  15.                 yield break;
  16.             for (int i = 0; i < root.Children.Count; i++)
  17.             {
  18.                 bool firstLineOfChild = true;
  19.                 bool lastChild = i == root.Children.Count - 1;
  20.                 foreach (var line in dump(root.Children[i]))
  21.                 {
  22.                     string prefix = lastChild
  23.                         ? (firstLineOfChild ? "└─" : "  ")
  24.                         : (firstLineOfChild ? "├─" : "│ ");
  25.                     yield return prefix + line;
  26.                     firstLineOfChild = false;
  27.                 }
  28.             }
  29.         }
  30.     }
clone this paste RAW Paste Data