-
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]: Implement ISpanParsable/Formattable for PhysicalAddress #83201
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationPhysicalAddress already provides These could now light up in various contexts, for example, While not being as important as API Proposalnamespace System.Net.NetworkInformation;
public class PhysicalAddress
+ : ISpanFormattable, ISpanParsable<PhysicalAddress>
{
// I(Span)Parsable overloads
// can delegate to existing (Try)Parse overloads. IFormatProvider provider would be explicitly ignored I presume.
+ public static bool IParsable<PhysicalAddress>.TryParse(string? s, IFormatProvider? provider, out PhysicalAddress? result);
+ public static bool ISpanParsable<PhysicalAddress>.TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out PhysicalAddress? result);
+ public static PhysicalAddress IParsable<PhysicalAddress>.Parse(string s, IFormatProvider? provider);
+ public static PhysicalAddress ISpanParsable<PhysicalAddress>.Parse(ReadOnlySpan<char> s, IFormatProvider? provider);
// IFormattable, can delegate to existing ToString(). format and provider would be explicitly ignored I presume.
+ public string IFormattable.ToString(string? format, IFormatProvider? formatProvider);
// ISpanFormattable
// Has no existing overloads to delegate to, should they be publicly provided like IPAddress?
+ public bool ISpanFormattable.TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider);
// e.g. Should we provide a following simpler overload like the convention used in IPAddress?
+ public bool TryFormat(Span<char> destination, out int charsWritten);
} API UsagePhysicalAddress physicalAddress = ...;
string s = $"The address is {physicalAddress}"; Alternative DesignsCould also just implement RisksNo response
|
Triage: putting to Future for now as there doesn't seem to be much customer ask |
Background and motivation
PhysicalAddress already provides
[Try]Parse
overloads and aToString
forIFormattable
. I propose giving some love to this type and implementingISpanFormattable
andISpanParsable<PhysicalAddress>
.These could now light up in various contexts, for example,
ISpanFormattable
would allowPhysicalAddress
light up in the string interpolated handlers.While not being as important as
IPAddress
and being hidden in namespace below, I'd argue PhysicalAddress is important enough networking primitive type to warrant these interfaces.API Proposal
API Usage
Alternative Designs
Note
Could also implement
IUtf8SpanFormattable
andIUtf8SpanParsable
but should that be separate proposal?Could also just implement
IFormattable
andIParsable
, but please, don't.Risks
No response
The text was updated successfully, but these errors were encountered: