Skip to content

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

Open
@carlreinke

Description

@carlreinke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions