-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationneeds-area-labelAn area label is needed to ensure this gets routed to the appropriate area ownersAn area label is needed to ensure this gets routed to the appropriate area owners
Description
Background and motivation
As part of #81500 :
Implement IUtf8SpanParsable on Guid. Additionally, add a utf8 Parse and TryParse that do not take the unused IFormatProvider parameter. This matches how ISpanParsable was implemented.
Draft PR: #105654
API Proposal
namespace System;
public readonly partial struct Guid
: ISpanFormattable,
IComparable,
IComparable<Guid>,
IEquatable<Guid>,
ISpanParsable<Guid>,
IUtf8SpanFormattable,
+ IUtf8SpanParsable<Guid>
{
+ public static Guid Parse(ReadOnlySpan<byte> utf8Text);
+ public static bool TryParse(ReadOnlySpan<byte> utf8Text, out Guid result);
+ public static Guid Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
+ public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Guid result);
}API Usage
var utf8GuidText = "{a8a110d5-fc49-43c5-bf46-802db8f843ff}"u8;
if (Guid.TryParse(utf8GuidText, out Guid guid))
{
//do something with guid
}Alternative Designs
No response
Risks
There are a few aspects to this that I am unsure about.
- Given that the
IFormatProviderparameter is unused, I thinkIUtf8SpanParsableought to be implemented explicitly. But that would not be consistent with theISpanParsableimplementation. - Should a utf8 version of
ParseExactandTryParseExactalso be added for consistency? - Guid has a constructor that takes a string, which is the same as calling
Guid.Parse(string). It also has a constructor that takes aReadOnlySpan<byte>, but this will not be equivalent to callingGuid.Parse(ReadOnlySpan<byte>), as that constructor deserializes from a binary representation of a Guid. Is this inconsistency a problem?
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationneeds-area-labelAn area label is needed to ensure this gets routed to the appropriate area ownersAn area label is needed to ensure this gets routed to the appropriate area owners