stakx / TypeNameFormatter

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

Constructed generic types using "captured" generic type parameters leads to incomplete output #18

Closed stakx closed 6 years ago

stakx commented 6 years ago
class Cup<T>
{
    public T[] Array;
    public (bool, T) Tuple;
}

Current, actual behavior:

typeof(Cup<>).GetField("Array").FieldType.GetFormattedName();
// => []

typeof(Cup<>).GetField("Tuple").FieldType.GetFormattedName();
// => (bool, )

Expected behavior:

In cases where a generic type parameter is used outside its generic type definition to construct another type, it would probably make sense to unconditionally imply TypeNameFormatOptions.GenericParameterNames:

typeof(Cup<>).GetField("Array").FieldType.GetFormattedName();
// => T[]

typeof(Cup<>).GetField("Tuple").FieldType.GetFormattedName();
// => (bool, T)

Or, with other words, it is only in generic type definitions that parameter names may be omitted.