Skip to content

Allow ref struct on Generic ThrowHelper methods #1127

@Avid29

Description

@Avid29

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

This use case has nothing specific in mind, but the point is you can imagine pattern matching a ref struct such as 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

No one assigned

    Labels

    feature request 📬A request for new changes to improve functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions