Skip to content

Commit

Permalink
GuidPolyfill.TryParse(CharSpan, IFormatProvider, out Guid)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Oct 2, 2024
1 parent d76228e commit 5127a80
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**API count: 360**
**API count: 363**
7 changes: 7 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@
* `Boolean TryParse(ReadOnlySpan<Char>, Globalization.NumberStyles, IFormatProvider, Byte&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse#system-byte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-byte@))


#### GuidPolyfill

* `Boolean TryParse(String, IFormatProvider, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse#system-guid-tryparse(system-string-system-iformatprovider-system-guid@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse#system-guid-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-guid@))
* `Boolean TryParse(ReadOnlySpan<Char>, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse?view=net-8.0#system-guid-tryparse(system-readonlyspan((system-char))-system-guid@))


#### DateTimePolyfill

* `Boolean TryParse(String, IFormatProvider, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-string-system-iformatprovider-system-datetime@))
Expand Down
8 changes: 1 addition & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`


**API count: 362**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
**API count: 360**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->


**See [Milestones](../../milestones?state=closed) for release notes.**
Expand Down Expand Up @@ -905,12 +905,6 @@ The class `Polyfill` includes the following extension methods:
* `Boolean TryParse(ReadOnlySpan<Char>, Globalization.NumberStyles, IFormatProvider, Byte&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse#system-byte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-byte@))


#### GuidPolyfill

* `Boolean TryParse(String, IFormatProvider, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse#system-guid-tryparse(system-string-system-iformatprovider-system-guid@))
* `Boolean TryParse(ReadOnlySpan<Byte>, IFormatProvider, Byte&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse#system-byte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-byte@))


#### DateTimePolyfill

* `Boolean TryParse(String, IFormatProvider, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-string-system-iformatprovider-system-datetime@))
Expand Down
22 changes: 17 additions & 5 deletions src/Polyfill/GuidPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,27 @@ public static bool TryParse(string? target, IFormatProvider? provider, out Guid
#endif

#if FeatureMemory

/// <summary>
/// Tries to parse a span of UTF-8 characters into a value.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse#system-guid-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-guid@)")]
public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider, out Guid result) =>
#if NET7_0_OR_GREATER
Guid.TryParse(target, provider, out result);
#else
Guid.TryParse(target.ToString(), out result);
#endif

/// <summary>
/// Tries to parse a span of UTF-8 characters into a value.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse#system-byte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-byte@)")]
public static bool TryParse(ReadOnlySpan<byte> target, IFormatProvider? provider, out byte result) =>
#if NET8_0_OR_GREATER
byte.TryParse(target, provider, out result);
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse?view=net-8.0#system-guid-tryparse(system-readonlyspan((system-char))-system-guid@)")]
public static bool TryParse(ReadOnlySpan<char> target, out Guid result) =>
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
Guid.TryParse(target, out result);
#else
byte.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result);
Guid.TryParse(target.ToString(), out result);
#endif

#endif
Expand Down
1 change: 1 addition & 0 deletions src/Tests/BuildApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void Run()
WriteHelper(types, "RegexPolyfill", writer, ref count);
WriteHelper(types, "StringPolyfill", writer, ref count);
WriteHelper(types, "BytePolyfill", writer, ref count);
WriteHelper(types, "GuidPolyfill", writer, ref count);
WriteHelper(types, "DateTimePolyfill", writer, ref count);
WriteHelper(types, "DateTimeOffsetPolyfill", writer, ref count);
WriteHelper(types, "DoublePolyfill", writer, ref count);
Expand Down

0 comments on commit 5127a80

Please sign in to comment.