Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private sealed class MyDumper
- {
- public static string Dump(Node root)
- {
- var sb = new StringBuilder();
- var workStack = new Stack<Helper>();
- workStack.Push(new Helper { Parent = null, CurrentNode = root, ParentIndent = string.Empty });
- while (workStack.Count > 0)
- {
- Helper current = workStack.Pop();
- if (current.Parent != null)
- {
- sb.Append(current.Parent.ParentIndent);
- current.ParentIndent = current.Parent.ParentIndent +
- (current.IsLast ? " " : "│") +
- " ";
- // my indent
- sb.Append(current.IsLast ? "└" : "├");
- sb.Append("-");
- }
- else current.ParentIndent = "";
- sb.AppendLine(current.CurrentNode.Text);
- for (int index = current.CurrentNode.Children.Count - 1; index >= 0; index--)
- {
- workStack.Push(new Helper
- {
- CurrentNode = current.CurrentNode.Children[index],
- Parent = current,
- IsLast = index == current.CurrentNode.Children.Count - 1
- });
- }
- }
- return sb.ToString();
- }
- private class Helper
- {
- public bool IsLast;
- public Node CurrentNode;
- public Helper Parent;
- public string ParentIndent;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement