public virtual string ToString(Func <IHierarchical <T>, string> formatter, bool convertToSingleLine = false) { var sbr = new StringBuilder(); sbr.AppendLine(convertToSingleLine ? formatter(this).Replace("\r", @"\r").Replace("\n", @"\n") : formatter(this)); var sb = new StringBuilder(); foreach (var node in Descendants) { sb.Append(convertToSingleLine ? formatter(node).Replace("\r", @"\r").Replace("\n", @"\n") : formatter(node)); sb.Insert(0, node == node.Parent.Children.Last() ? "└─" : "├─"); for (int i = 0; i < node.Ancestors.Count() - (Ancestors?.Count() ?? 0) - 1; i++) { sb.Insert(0, node.Ancestors.ElementAt(i) == node.Ancestors.ElementAt(i + 1).Children.Last() ? " " : "│ "); } sbr.AppendLine(sb.ToString()); sb.Clear(); } return(sbr.ToString()); }