title: Pretty printing a collection recursively
body: <p>I've seen lots of questions about this, but I haven't seen any about doing it recursively.  I've created some extension methods that do a pretty good job of pretty printing at a depth of 1.  It looks like this:</p>
  
  <pre><code>    public static string PrettyToString&lt;K, V&gt;(this Dictionary&lt;K, V&gt; dictionary)
      {
          string result = "{";
          foreach (var kvp in dictionary)
          {
              result += $"({kvp.Key}, {kvp.Value}) ";
          }
          result += "}";
          return result;
      }
  
      public static string PrettyToString&lt;T&gt;(this List&lt;T&gt; list)
      {
          string result = "{";
          foreach (var element in list)
          {
              result += $"{element}, ";
          }
          result += "}";
          return result;
      }
  
      public static string PrettyToString&lt;T&gt;(this T [] list)
      {
          string result = "{";
          foreach (var element in list)
          {
              result += $"{element}, ";
          }
          result += "}";
          return result;
      }
  </code></pre>
  
  <p>But, what if <code>K</code>, <code>V</code>, or <code>T</code> is another collection like a <code>List</code> or a <code>Dictionary</code>?  I want to recursively pretty print, but I'm not sure how to do that.  As a result, my output looks like this:</p>
  
  <pre><code>{(foo, System.Collections.Generic.Dictionary`2[System.String,System.Boolean])...
  </code></pre>
  
  <p>I want it to look like this instead:</p>
  
  <pre><code>    {(foo, {(bar, true)})...
  </code></pre>
  
  <p>I'm looking for methods that print recursively regardless of the nested types:</p>
  
  <pre><code>var x = new List&lt;Dictionary&lt;string, string&gt;&gt;();
  var y = new Dictionary&lt;Dictionary&lt;string, string&gt;, string&gt;&gt;();
  var z = new Dictionary&lt;Dictionary&lt;string, string&gt;, List&lt;string&gt;&gt;&gt;();
  ...
  x.PrettyToString();
  y.PrettyToString();
  z.PrettyToString();
  </code></pre>
  
  <p>Should all recursively print out the contents.  How do I achieve that?</p>