Skip to content

Instantly share code, notes, and snippets.

@mhinze
Created September 30, 2010 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinze/605256 to your computer and use it in GitHub Desktop.
Save mhinze/605256 to your computer and use it in GitHub Desktop.
public static string Prettify(this Type type)
{
var provider = new Microsoft.CSharp.CSharpCodeProvider();
return provider.GetTypeOutput(new System.CodeDom.CodeTypeReference(type));
}
@mhinze
Copy link
Author

mhinze commented Sep 30, 2010

public class TypeExtensionsTester : TestBase
{
    [Test]
    public void Should_format_generic_type()
    {
        const string expected = "SomeApp.Reporting.UnitTests.Core.Domain.SomeType<SomeApp.Reporting.UnitTests.Core.Domain.Plug>";
        typeof (SomeType<Plug>).Prettify().ShouldEqual(expected);
    }

    [Test]
    public void Should_format_type()
    {
        const string expected = "SomeApp.Reporting.UnitTests.Core.Domain.SomeType";
        typeof (SomeType).Prettify().ShouldEqual(expected);
    }
}

public class SomeType {}

public class Plug {}

public class SomeType<T> {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment