Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeUtil.ToCSharpString(this Type) does not handle nested generic types correctly #365

Closed
pmg23 opened this issue May 31, 2018 · 4 comments

Comments

@pmg23
Copy link

pmg23 commented May 31, 2018

The useful extension method TypeUtil.ToCSharpString(this Type) does not correctly deal with types nested within generic types [as of Core 4.2.1]. For example:

internal class A<T1>
{
    internal class B {}
    internal class C<T2> {}
}

Assert.That(typeof(A<string>.B).ToCSharpString(),
        Is.EqualTo("A<String>.B")); // FAIL: actually "A<·T1·>.B<String>"
Assert.That(typeof(A<string>.C<int>).ToCSharpString(),
        Is.EqualTo("A<String>.C<Int32>")); // FAIL: actually "A<·T1·>.C<String, Int32>"
@stakx
Copy link
Member

stakx commented May 31, 2018

(Shameless advertisement:)

Type name formatting is surprisingly complex because there are quite a few corner cases to deal with. I happen to have written a small library recently (stakx/TypeNameFormatter) that would solve this problem. It's available as a source code NuGet package.

@stakx
Copy link
Member

stakx commented May 31, 2018

That being said, I cannot seem to find a method TypeUtil.ToCSharpString(this Type) in Castle Core (this repository). Did you mean this method in Castle Windsor (castleproject/Windsor)?

@stakx
Copy link
Member

stakx commented May 31, 2018

@pmg23, I've migrated this issue over to castleproject/Windsor#404, so please subscribe to the new issue. I'm closing this one here.

@stakx stakx closed this as completed May 31, 2018
@pmg23
Copy link
Author

pmg23 commented May 31, 2018

Hi @stakx. Thanks for the quick response. I did indeed mean that one from Windsor. (The namespace, which I should have mentioned is Castle.Core.Internal, confused me.)

We'll definitely look into using stakx/TypeNameFormatter. Thanks for sharing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants