stakx / TypeNameFormatter

A small .NET library for formatting type names à la C#.
MIT License
33 stars 4 forks source link

Regression in 1.0.0-beta2: Closed generic type enclosed in non-generic type causes exception #28

Closed stakx closed 6 years ago

stakx commented 6 years ago
class Outer
{
    public class Inner<T> { }
}

typeof(Outer.Inner<int>).GetFormattedName();  // *boom*

The problem lies here:

https://github.com/stakx/TypeNameFormatter/blob/4d3f70a706477d929888490a6fe4abc55a1034f9/src/TypeNameFormatter/TypeNameFormatter.cs#L134-L139

This only checks whether the innermost type (typeWithGenericTypeArgs) is generic, but if we're formatting a non-generic enclosing type, type.GetGenericTypeDefinition will bomb.