-
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
Equals/GetHashCode for UnixDomainSocketEndPoint #69488
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationMy network framework uses EndPoint class as abstraction layer to represent the peer address. It is easy to determine whether the two endpoints represent the same address using Equals method. However, UnixDomainSocketEndPoint doesn't override necessary methods in contrast to IPEndPoint and DnsEndPoint. API Proposalnamespace System.Net.Sockets;
public sealed class UnixDomainSocketEndPoint : EndPoint
{
public override bool Equals(object? other);
public override int GetHashCode();
} API Usagevar set = new HashSet(); set.Add(new UnixDomainSocketEndPoint("@abstract")); Alternative DesignsImplement custom equality logic: static bool EndPointsAreEqual(EndPoint x, EndPoint y)
{
if (x is UnixDomainSocketEndPoint uds1)
return y is UnixDomainSocketEndPoint uds2 && string.Equals(uds1.ToString(), uds2.ToString(), StringComparison.Ordinal);
return object.Equals(x, y);
} RisksBreaks behavior of default implementation of Equals and GetHashCode.
|
Given that both IPEndPoint and DnsEndPoint override these, it's reasonable for UnixDomainSocketEndPoint to as well. I don't think this really needs to be considered an API proposal. Technically it could break someone relying on Equals providing reference equality, but the chances of that are slim, especially since that's not what it means generally when using the base EndPoint. |
@stephentoub , if so, I'm ready to make a PR. |
Triage: that makes sense; we would gladly accept the contribution @sakno |
@CarnaViire , PR is ready for review. |
Background and motivation
My network framework uses EndPoint class as abstraction layer to represent the peer address. It is easy to determine whether the two endpoints represent the same address using Equals method. However, UnixDomainSocketEndPoint doesn't override necessary methods in contrast to IPEndPoint and DnsEndPoint.
API Proposal
API Usage
var set = new HashSet();
set.Add(new UnixDomainSocketEndPoint("@abstract"));
set.Contains(new UnixDomainSocketEndPoint("@abstract"));
Alternative Designs
Implement custom equality logic:
Risks
Breaks behavior of default implementation of Equals and GetHashCode.
The text was updated successfully, but these errors were encountered: