-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: Consider support for IEquatable<Uri>
on System.Uri
#97940
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationFor a long time, the API Proposalnamespace System;
public class Uri : IEquatable<Uri>, ...
{
bool IEquatable<Uri>.Equals(Uri other);
...
} API UsageIEquatable<Uri> a = new Uri("https://example.com/a");
IEquatable<Uri> b = new Uri("https://example.com/b");
Console.WriteLine("Equals? {0}", a.Equals(b)); Alternative DesignsNo response RisksNo response
|
IEquatable<Uri>
on System.Uri
I don't see a benefit here; |
This would allow Api Usagebool AreEqual(Uri[] left, Uri[] right)
{
return left.AsSpan().SequenceEqual(right.AsSpan());
} |
|
If implementing |
Dictionary requires |
Isn't overriding the default |
This seems reasonable to me. The main benefits I see are:
namespace System;
-public partial class Uri : ISpanFormattable, ISerializable
+public partial class Uri : ISpanFormattable, ISerializable, IEquatable<Uri>
{
// Existing
public override bool Equals(object? comparand);
+ public bool Equals(Uri? other);
} @dotnet/ncl any thoughts against marking this one as ready for review? |
Seems fine. |
namespace System;
-public partial class Uri : ISpanFormattable, ISerializable
+public partial class Uri : ISpanFormattable, ISerializable, IEquatable<Uri>
{
// Existing
public override bool Equals(object? comparand);
+ public bool Equals([NotNullWhen(true)] Uri? other);
} |
Might be a dumb question, but what is the behavior for internationalized domain names? In other words: Are these two equal?
|
The behavior would be the same with existing The |
As mentioned, the new API would exactly match the behavior of the existing one.
The docs suggest they should, but that's currently not the case. That's most likely a bug we should track separately though. |
Edited by @MihaZupan on 2024-02-16
Background and motivation
For a long time, the
System.Uri
type has provided equality comparison operations via theobject.Equals(object?)
method and theoperator ==()
&operator !=()
operators. Therefore, there is no reason not to further implement theIEquatable<Uri>
interface.API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: