Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Eric Lippert's challenge

By: a guest on Sep 10th, 2010  |  syntax: C#  |  size: 0.68 KB  |  views: 41  |  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.         return root.Text + "\n" + DumpChildren( root, "" );
  6.     }
  7.     static private string DumpChildren(Node node, string indent)
  8.     {
  9.         return node.Children.Count > 0
  10.             ?   string.Join( "",  node.Children.Take(node.Children.Count - 1).ToList()
  11.                     .ConvertAll( new Converter<Node, String>( child => string.Format("{0}├─{1}\n{2}", indent, child.Text, DumpChildren(child, indent + "│ ") ) ) ).ToArray() )
  12.                 + string.Format("{0}└─{1}\n{2}", indent, node.Children.Last().Text, DumpChildren(node.Children.Last(), indent + "  ") )
  13.             : "";
  14.     }
  15. }