title: How do I print out a tree structure?
body: <p>I'm trying to improve performance in our app.  I've got performance information in the form of a tree of calls, with the following node class:</p>
  
  <pre><code>public class Node
  {
      public string Name; // method name
      public decimal Time; // time spent in method
      public List&lt;Node&gt; Children;
  }
  </code></pre>
  
  <p>I want to print out the tree such that I can see lines between the nodes - something like in <a href="https://stackoverflow.com/questions/1581559/ascii-library-for-creating-pretty-directory-trees">this question</a>.  What's an algorithm I can use in C# for doing that?</p>
  
  <p>Edit: Obviously I need to use recursion - but my attempts keep putting the lines in the wrong places.  What I'm asking for is a specific algorithm that will print the tree in a nice manner - the details of when to print a vertical line and when to print a horizontal one.</p>
  
  <p>Edit: It isn't sufficient just to use copies of a string to indent the nodes.  I'm not looking for</p>
  
  <pre><code>A
  |-B
  |-|-C
  |-|-D
  |-|-|-E
  |-F
  |-|-G
  </code></pre>
  
  <p>it has to be</p>
  
  <pre><code>A
  +-B
  | +-C
  | +-D
  |   +-E
  +-F
    +-G
  </code></pre>
  
  <p>or anything similar, so long as the tree structure is visible.  Notice that C and D are indented differently to G - I can't just use a repeated string to indent the nodes.</p>