Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed class Dumper
- {
- static public string Dump(Node root)
- {
- var sb = new StringBuilder();
- Action<Node, string> action = null;
- action = (node, indent) =>
- {
- // Precondition: indentation and prefix has already been output
- // Precondition: indent is correct for node's *children*
- sb.AppendLine(node.Text);
- for (int i = 0; i < node.Children.Count; ++i)
- {
- bool last = i == node.Children.Count - 1;
- var child = node.Children[i];
- sb.Append(indent);
- sb.Append(last ? '└' : '├');
- sb.Append('─');
- action(child, indent + (last ? " " : "│ "));
- }
- };
- action(root, "");
- return sb.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement