Skip to content

[API Proposal]: Implement IParsable<TSelf> et cetera on IPEndPoint #114405

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

Open
carlreinke opened this issue Apr 8, 2025 · 3 comments
Open

[API Proposal]: Implement IParsable<TSelf> et cetera on IPEndPoint #114405

carlreinke opened this issue Apr 8, 2025 · 3 comments
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Net
Milestone

Comments

@carlreinke
Copy link
Contributor

carlreinke commented Apr 8, 2025

Background and motivation

IPEndPoint has Parse methods. It should implement IParsable<TSelf> and the other interfaces that usually go with that.

API Proposal

Updated by @MihaZupan on 2025-05-20 to add all the methods

namespace System.Net;

public partial class IPEndPoint : EndPoint
+   , ISpanFormattable, ISpanParsable<IPEndPoint>, IUtf8SpanFormattable, IUtf8SpanParsable<SIPEndPoint>
{
    public static IPEndPoint Parse(ReadOnlySpan<char> s);
    public static IPEndPoint Parse(string s);
    public static bool TryParse(ReadOnlySpan<char> s, [NotNullWhen(true)] out IPEndPoint? result);
    public static bool TryParse(string s, [NotNullWhen(true)] out IPEndPoint? result);

+   public static IPEndPoint Parse(ReadOnlySpan<byte> utf8Text);
+   static IPEndPoint ISpanParsable<IPEndPoint>.Parse(ReadOnlySpan<char> s, IFormatProvider? provider);
+   static IPEndPoint IParsable<IPEndPoint>.Parse(string s, IFormatProvider? provider);
+   static IPEndPoint IUtf8SpanParsable<IPEndPoint>.Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);

+   public static bool TryParse(ReadOnlySpan<byte> utf8Text, [NotNullWhen(true)] out IPEndPoint? result);
+   static bool ISpanParsable<IPEndPoint>.TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, [NotNullWhen(true)] out IPEndPoint? result);
+   static bool IParsable<IPEndPoint>.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [NotNullWhen(true)] out IPEndPoint? result);
+   static bool IUtf8SpanParsable<IPEndPoint>.TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, [NotNullWhen(true)] out IPEndPoint? result);

+   string IFormattable.ToString(string? format, IFormatProvider? formatProvider);
+   public bool TryFormat(Span<char> destination, out int charsWritten);
+   public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten);
+   bool ISpanFormattable.TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider);
+   bool IUtf8SpanFormattable.TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider);
}

API Usage

The type will be usable where generic type constraints require an IParsable<TSelf> or other of the added interfaces.

Alternative Designs

No response

Risks

No response

@carlreinke carlreinke added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Apr 8, 2025
@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 8, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 8, 2025
@MihaZupan MihaZupan added area-System.Net and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 8, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@pentp
Copy link
Contributor

pentp commented Apr 11, 2025

Should also include IUtf8SpanFormattable, IUtf8SpanParsable<IPEndPoint> to match IPAddress.

@MihaZupan MihaZupan removed their assignment May 20, 2025
@MihaZupan
Copy link
Member

Updated the proposal with all the methods, mirroring IPAddress.
Format is ignored as with IPAddress, so those overloads are explicit instead.

Triage: Seems reasonable to match IPAddress here, also contributes to #81500 (comment). Making as ready for review, Future.

@MihaZupan MihaZupan added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged New issue has not been triaged by the area owner labels May 20, 2025
@MihaZupan MihaZupan added this to the Future milestone May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Net
Projects
None yet
Development

No branches or pull requests

3 participants