A neater GetType().ToString() for closed generics
<p>I can't believe that this hasn't been asked before but as I am unable to find this particular "needle" in the stackoverflow haystack I'm asking it.</p>

<p>I would like a neater implementation of GetType().ToString() for closed generic types. By neater I mean that I would like the ToString() call to return a string in the format I would have typed into the development environment.</p>

<p>The default GetType().ToString() on a closed generic will place `<em>n</em> where <em>n</em> is the number of types, and uses [ ]'s instead of &lt;>'s. </p>

<p>Anyway ... to the code.</p>

<p>given the following classes:</p>

<pre><code>A a = new A();
C&lt;A&gt; c = new C&lt;A&gt;();
D&lt;A, B&gt; d = new D&lt;A, B&gt;();
E&lt;B, C&lt;A&gt;, D&lt;A, B&gt;&gt; e = new E&lt;B, C&lt;A&gt;, D&lt;A, B&gt;&gt;();
</code></pre>

<p>The default <code>.ToString()</code> returns:</p>

<pre><code>AAA.Events.A
AAA.Events.C`1[AAA.Events.A]
AAA.Events.D`2[AAA.Events.A,AAA.Events.B]
AAA.Events.E`3[AAA.Events.B,AAA.Events.C`1[AAA.Events.A],AAA.Events.D`2
</code></pre>

<p>I've written some basic old school (pre linq) code to produce:</p>

<pre><code>AAA.Events.A
AAA.Events.C&lt;AAA.Events.A&gt;
AAA.Events.D&lt;AAA.Events.A,AAA.Events.B&gt;
AAA.Events.E&lt;AAA.Events.B,AAA.Events.C&lt;AAA.Events.A&gt;,AAA.Events.D&lt;AAA.Events.A,AAA.Events.B&gt;&gt;
</code></pre>

<p>But I would really like it to return:</p>

<pre><code>A
C&lt;A&gt;
D&lt;A,B&gt;
E&lt;B,C&lt;A&gt;,D&lt;A,B&gt;&gt;
</code></pre>

<p>Here's the shoddy code I have written to demonstrate my intent:</p>

<pre><code>public static string NeaterString(this Type t)
{
    string neater = t.ToString();
    if (neater.Contains('`'))
    {
        while (neater.Contains('`'))
        {
            neater = neater.Remove(neater.IndexOf('`'), 2);
        }
        return neater.Replace('[', '&lt;').Replace(']', '&gt;');
    }
    else return neater; 
}
</code></pre>
