Describe the bug
TypeExtensions.ToTypeString throws an ArgumentOutOfRangeException for open generic types.
Example on .NET Fiddle
Regression
No response
Steps to reproduce
- Run the following code:
using CommunityToolkit.Diagnostics;
System.Console.WriteLine(typeof(Foo<>).ToTypeString());
public sealed record Foo<T>;
- Observe the exception is thrown
Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
at CommunityToolkit.Diagnostics.TypeExtensions.<ToTypeString>g__FormatDisplayString|2_0(Type type, Int32 genericTypeOffset, ReadOnlySpan`1 typeArguments) in /_/src/CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs:line 110
at CommunityToolkit.Diagnostics.TypeExtensions.<ToTypeString>g__FormatDisplayString|2_0(Type type, Int32 genericTypeOffset, ReadOnlySpan`1 typeArguments) in /_/src/CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs:line 131
at CommunityToolkit.Diagnostics.TypeExtensions.<>c.<ToTypeString>b__2_3(Type t) in /_/src/CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs:line 114
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
at System.String.Join(String separator, IEnumerable`1 values)
at CommunityToolkit.Diagnostics.TypeExtensions.<ToTypeString>g__FormatDisplayString|2_0(Type type, Int32 genericTypeOffset, ReadOnlySpan`1 typeArguments) in /_/src/CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs:line 114
at CommunityToolkit.Diagnostics.TypeExtensions.<>c.<ToTypeString>b__2_1(Type t) in /_/src/CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs:line 164
at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
at CommunityToolkit.Diagnostics.TypeExtensions.ToTypeString(Type type) in /_/src/CommunityToolkit.Diagnostics/Extensions/TypeExtensions.cs:line 138
at Program.<Main>$(String[] args)
Command terminated by signal 6
Expected behavior
typeof(Foo<>).ToTypeString() should produce the text Foo<>
Screenshots
No response
IDE and version
Rider
IDE version
#RD-223.8617.53
Nuget packages
Nuget package version(s)
8.1.0
Additional context
No response
Help us help you
No, just wanted to report this
Describe the bug
TypeExtensions.ToTypeStringthrows anArgumentOutOfRangeExceptionfor open generic types.Example on .NET Fiddle
Regression
No response
Steps to reproduce
Expected behavior
typeof(Foo<>).ToTypeString()should produce the textFoo<>Screenshots
No response
IDE and version
Rider
IDE version
#RD-223.8617.53
Nuget packages
Nuget package version(s)
8.1.0
Additional context
No response
Help us help you
No, just wanted to report this