GDS Ascii Tree GDS Ascii Tree
Use this package to easily create an ASCII tree from any structure or list.


Code Samples:
      // SIMPLE PARENT-CHILD STRUCTURE, from Node class defined above
      Node Tree = new Node() { Name = "Tree" };
      Tree.Childs = new List<Node>()
      {
        new Node() { Name = "Child 1", Age = 1 },
        new Node() { Name = "Child 2", Age = 2,
          Childs = new List<Node>(){
            new Node() { Name ="Child 3", Age = 3 },
            new Node() { SpecialProperty = new SpecialPropertyClass(){ X = "X", Y = 1, }, Age = 4 }
          }
        },
        new Node() { Name ="Child 5", Age = 5 }
      };
  


The classes used in the sample above:
  public class NestedClassProperty
  {
    public NestedClassProperty Property { get; set; }
    public string Name { get; set; }
  }
  public class SpecialPropertyClass
  {
    public string X { get; set; }
    public int Y { get; set; }
    public override string ToString()
    {
      return X;
    }
  }
  public class Node
  {
    public string Name { get; set; }
    public int Age { get; set; }
    public NestedClassProperty NestProperty { get; set; }
    public SpecialPropertyClass SpecialProperty { get; set; }
    public List<Node> Childs { get; set; } = new List<Node>();
  }    
  
  

How it looks:
console

WPF Example: MainWindow.xaml.cs
    private void cmdMakeAscii_Click(object sender, RoutedEventArgs e)
    {
      txtAscii.Text = ASCIITree.GetTree(Tree.Items, "{Header??GetType().Name}", "Items", "Tree");
    }

    private void cmdMakeAsciiFromVisualtree_Click(object sender, RoutedEventArgs e)
    {
      txtAscii.Text = ASCIITree.GetTree(this.grid, "{Header??Name??$type$.Name}", "Children??Child??Items");
    }    
  

MainWindow.xaml
<Window x:Class="WpfApp4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp4"
        mc:Ignorable="d"
        Title="MainWindow" Height="438.35" Width="679.045" MinHeight="200" MinWidth="500" WindowStartupLocation="CenterScreen">
  <Grid Name="grid">
    <TreeView HorizontalAlignment="Left" Margin="10,10,0,10" Width="254" Name="Tree">
      <TreeView.Items>
        <TreeViewItem Header="Root" IsExpanded="True">
          <TreeViewItem.Items>
            <TreeViewItem Header="" IsExpanded="True" >
              <TreeViewItem.Items>
                <TreeViewItem Header="Sub Sub 1" />
                <TreeViewItem Header="Sub Sub 2" />
              </TreeViewItem.Items>
            </TreeViewItem>
            <TreeViewItem Header="Sub 2" IsExpanded="True"  />
            <TreeViewItem Header="Sub 3" IsExpanded="True"  />
          </TreeViewItem.Items>
        </TreeViewItem>
      </TreeView.Items>
    </TreeView>
    <Button Name="cmdMakeAscii" Click="cmdMakeAscii_Click" Content="Generate Treeview Ascii" HorizontalAlignment="Left" Margin="269,10,0,0" VerticalAlignment="Top" Width="151"/>
    <Border Margin="269,60,10,10" BorderBrush="Gray" BorderThickness="1" Padding="6">
      <TextBox TextWrapping="Wrap" Text="" FontFamily="Courier New" FontSize="16" Name="txtAscii" />
    </Border>
    <Label Content="Ascii:" HorizontalAlignment="Left" Margin="269,34,0,0" VerticalAlignment="Top" Padding="0,5,5,5"/>
    <Button x:Name="cmdMakeAsciiFromVisualtree" Click="cmdMakeAsciiFromVisualtree_Click" Content="Generate VisualTree Ascii" HorizontalAlignment="Left" Margin="425,10,0,0" VerticalAlignment="Top" Width="151"/>
  </Grid>
</Window>

  

How it looks:
wpf