-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Removes IEquatable constraint from ThrowIfEqual/NotEqual #118291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tagging subscribers to this area: @dotnet/area-system-runtime |
This likely needs to wait for .NET 11 since we are locking down for RC1. However, this is something that I would be willing to take a bar check around given how frequently its been asked for and its a minor change just relaxing a constraint. -- CC. @jeffhandley for secondary input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes the IEquatable<T>
constraint from the ThrowIfEqual
and ThrowIfNotEqual
methods in ArgumentOutOfRangeException
, allowing these methods to work with any type rather than just those implementing IEquatable<T>
. The methods will continue to use EqualityComparer<T>.Default.Equals
for equality comparisons, which provides appropriate equality behavior for all types.
Key changes:
- Removes generic type constraints from
ThrowIfEqual
andThrowIfNotEqual
methods - Updates corresponding test helper methods to match the new signatures
- Maintains existing functionality while broadening method applicability
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/libraries/System.Private.CoreLib/src/System/ArgumentOutOfRangeException.cs |
Removes IEquatable<T> constraint from method signatures |
src/libraries/System.Runtime/ref/System.Runtime.cs |
Updates public API reference to reflect constraint removal |
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArgumentOutOfRangeExceptionTests.cs |
Updates test helper methods to match new method signatures |
/backport to release/10.0 I'm supportive of this coming in for 10.0 RC2 |
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17387958834 |
Removes the
IEquatable
constraint from theThrowIfEqual
andThrowIfNotEqual
methods inArgumentOutOfRangeException
.IEquatable
, relying onEqualityComparer.Default.Equals
for equality comparisons.Resolves #118053