Advertisement
Guest User

Olostan

a guest
Sep 15th, 2010
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1.     static public string Dump(Node root)
  2.     {
  3.       return string.Join("",
  4.         new[] { root.Text + "\n" }.Concat(
  5.           root.Children.Take(root.Children.Count - 1).Select(Dump).Select(x => "├─" + x.TrimEnd().Replace("\n", "\n│ ")+"\n"))
  6.           .Concat(root.Children.Skip(root.Children.Count - 1).Select(Dump).Select(x => "└─" + x.TrimEnd().Replace("\n", "\n ")+"\n"))
  7.           .ToArray());      
  8.     }
  9.  
  10.  
  11.     static public string Dump(Node root)
  12.     {
  13.       Func<Func<IEnumerable<Node>, int, IEnumerable<Node>>, string, string, Func<IEnumerable<Node>, IEnumerable<string>>> func =
  14.         (take, a, b) => source => take(source, root.Children.Count - 1).Select(Dump)
  15.           .Select(x => string.Format("{0}─{1}\n", a, x.TrimEnd().Replace("\n", "\n"+b+" ")));
  16.      
  17.       return string.Join("",
  18.         new[] { root.
  19.           Text + "\n" }.Concat(
  20.           new []{func(Enumerable.Take,"├","│"),func(Enumerable.Skip,"└"," ")}.SelectMany(f => f(root.Children)))
  21.           .ToArray());
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement