View difference between Paste ID: yf0hLnFs and
SHOW: | | - or go back to the newest paste.
1-
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
    }