-
Notifications
You must be signed in to change notification settings - Fork 363
Open
Labels
feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionality
Description
Overview
This would allow ref structs to be used in pattern matching with a ThrowHelper case, using the new allow ref struct "anti-constraint".
API breakdown
This changes nothing except allowable use cases for existing ThrowHelper APIs.
Usage example
I encountered a situation in my code where I wanted to pattern match and return a ref struct. I found I could not use the ThrowHelper because it was a ref struct.
Here's an example of another imaginable situation utilizing the Span<T>.
Span<int> span = x switch
{
0 => stackalloc int[size],
1 => new int[size],
2 => something.AsSpan(),
_ => ThrowHelper.ThrowArgumentOutOfRangeException<Span<int>>(),
};Breaking change?
No
Alternatives
throw without ThrowHelper
Additional context
This will require .NET 9 and C# version 13
Help us help you
Yes, I'd like to be assigned to work on this item
Metadata
Metadata
Assignees
Labels
feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionality