From e02b5686ac850914edbbfdbd56acd029bdf686e7 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 19 Dec 2024 20:32:35 +1100 Subject: [PATCH] Fix LongPolyfill incorrectly extending int (#264) --- src/Polyfill/Numbers/BytePolyfill.cs | 12 ++----- src/Polyfill/Numbers/DoublePolyfill.cs | 12 ++----- src/Polyfill/Numbers/IntPolyfill.cs | 12 ++----- src/Polyfill/Numbers/LongPolyfill.cs | 48 +++++++++++--------------- src/Polyfill/Numbers/SBytePolyfill.cs | 12 ++----- src/Polyfill/Numbers/ShortPolyfill.cs | 12 ++----- src/Polyfill/Numbers/UIntPolyfill.cs | 12 ++----- src/Polyfill/Numbers/ULongPolyfill.cs | 12 ++----- src/Polyfill/Numbers/UShortPolyfill.cs | 12 ++----- 9 files changed, 45 insertions(+), 99 deletions(-) diff --git a/src/Polyfill/Numbers/BytePolyfill.cs b/src/Polyfill/Numbers/BytePolyfill.cs index d8ddc86c..59231d53 100644 --- a/src/Polyfill/Numbers/BytePolyfill.cs +++ b/src/Polyfill/Numbers/BytePolyfill.cs @@ -36,10 +36,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out byte public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out byte result) => #if NET8_0_OR_GREATER byte.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - byte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - byte.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + byte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -71,10 +69,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out byte result) => #if NET8_0_OR_GREATER byte.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - byte.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - byte.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + byte.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -84,10 +80,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out byte result) => #if NET8_0_OR_GREATER byte.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - byte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - byte.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + byte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/DoublePolyfill.cs b/src/Polyfill/Numbers/DoublePolyfill.cs index 6a551075..2c594df3 100644 --- a/src/Polyfill/Numbers/DoublePolyfill.cs +++ b/src/Polyfill/Numbers/DoublePolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out doubl public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out double result) => #if NET8_0_OR_GREATER double.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - double.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Float, provider, out result); #else - double.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Float, provider, out result); + double.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Float, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out double result) => #if NET8_0_OR_GREATER double.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - double.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - double.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + double.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out double result) => #if NET8_0_OR_GREATER double.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - double.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Float, null, out result); #else - double.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Float, null, out result); + double.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Float, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/IntPolyfill.cs b/src/Polyfill/Numbers/IntPolyfill.cs index f9e185a2..60dd304e 100644 --- a/src/Polyfill/Numbers/IntPolyfill.cs +++ b/src/Polyfill/Numbers/IntPolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out int r public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out int result) => #if NET8_0_OR_GREATER int.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - int.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - int.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + int.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out int result) => #if NET8_0_OR_GREATER int.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - int.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - int.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + int.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out int result) => #if NET8_0_OR_GREATER int.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - int.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - int.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + int.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/LongPolyfill.cs b/src/Polyfill/Numbers/LongPolyfill.cs index 9503af92..848c4bae 100644 --- a/src/Polyfill/Numbers/LongPolyfill.cs +++ b/src/Polyfill/Numbers/LongPolyfill.cs @@ -20,11 +20,11 @@ static class LongPolyfill /// Tries to parse a string into a value. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-string-system-iformatprovider-system-int64@) - public static bool TryParse(string? target, IFormatProvider? provider, out int result) => + public static bool TryParse(string? target, IFormatProvider? provider, out long result) => #if NET7_0_OR_GREATER - int.TryParse(target, provider, out result); + long.TryParse(target, provider, out result); #else - int.TryParse(target, NumberStyles.Integer, provider, out result); + long.TryParse(target, NumberStyles.Integer, provider, out result); #endif #if FeatureMemory @@ -32,72 +32,66 @@ public static bool TryParse(string? target, IFormatProvider? provider, out int r /// Tries to parse a span of UTF-8 characters into a value. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int64@) - public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out int result) => + public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out long result) => #if NET8_0_OR_GREATER - int.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - int.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); + long.TryParse(target, provider, out result); #else - int.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + long.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-readonlyspan((system-char))-system-int64@) - public static bool TryParse(ReadOnlySpan target, out int result) => + public static bool TryParse(ReadOnlySpan target, out long result) => #if NETCOREAPP2_0 || NETFRAMEWORK || NETSTANDARD2_0 - int.TryParse(target.ToString(), out result); + long.TryParse(target.ToString(), out result); #else - int.TryParse(target, out result); + long.TryParse(target, out result); #endif /// /// Tries to parse a span of characters into a value. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-int64@) - public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out int result) => + public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out long result) => #if NET7_0_OR_GREATER - int.TryParse(target, provider, out result); + long.TryParse(target, provider, out result); #else - int.TryParse(target.ToString(), NumberStyles.Integer, provider, out result); + long.TryParse(target.ToString(), NumberStyles.Integer, provider, out result); #endif /// /// Tries to parse a span of UTF-8 characters into a value. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int64@) - public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out int result) => + public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out long result) => #if NET8_0_OR_GREATER - int.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - int.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); + long.TryParse(target, style, provider, out result); #else - int.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + long.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int64@) - public static bool TryParse(ReadOnlySpan target, out int result) => + public static bool TryParse(ReadOnlySpan target, out long result) => #if NET8_0_OR_GREATER - int.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - int.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); + long.TryParse(target, out result); #else - int.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + long.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse#system-int64-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int64@) - public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out int result) => + public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out long result) => #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETFRAMEWORK - int.TryParse(target.ToString(), style, provider, out result); + long.TryParse(target.ToString(), style, provider, out result); #else - int.TryParse(target, style, provider, out result); + long.TryParse(target, style, provider, out result); #endif #endif } \ No newline at end of file diff --git a/src/Polyfill/Numbers/SBytePolyfill.cs b/src/Polyfill/Numbers/SBytePolyfill.cs index 9b2b5c50..a1d0f334 100644 --- a/src/Polyfill/Numbers/SBytePolyfill.cs +++ b/src/Polyfill/Numbers/SBytePolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out sbyte public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out sbyte result) => #if NET8_0_OR_GREATER sbyte.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - sbyte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - sbyte.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + sbyte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out sbyte result) => #if NET8_0_OR_GREATER sbyte.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - sbyte.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - sbyte.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + sbyte.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out sbyte result) => #if NET8_0_OR_GREATER sbyte.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - sbyte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - sbyte.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + sbyte.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/ShortPolyfill.cs b/src/Polyfill/Numbers/ShortPolyfill.cs index d82f9d25..c085479c 100644 --- a/src/Polyfill/Numbers/ShortPolyfill.cs +++ b/src/Polyfill/Numbers/ShortPolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out short public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out short result) => #if NET8_0_OR_GREATER short.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - short.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - short.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + short.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out short result) => #if NET8_0_OR_GREATER short.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - short.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - short.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + short.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out short result) => #if NET8_0_OR_GREATER short.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - short.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - short.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + short.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/UIntPolyfill.cs b/src/Polyfill/Numbers/UIntPolyfill.cs index d763e34b..93e80a98 100644 --- a/src/Polyfill/Numbers/UIntPolyfill.cs +++ b/src/Polyfill/Numbers/UIntPolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out uint public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out uint result) => #if NET8_0_OR_GREATER uint.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - uint.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - uint.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + uint.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out uint result) => #if NET8_0_OR_GREATER uint.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - uint.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - uint.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + uint.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out uint result) => #if NET8_0_OR_GREATER uint.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - uint.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - uint.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + uint.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/ULongPolyfill.cs b/src/Polyfill/Numbers/ULongPolyfill.cs index 36745568..2b8ebe9d 100644 --- a/src/Polyfill/Numbers/ULongPolyfill.cs +++ b/src/Polyfill/Numbers/ULongPolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out ulong public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out ulong result) => #if NET8_0_OR_GREATER ulong.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - ulong.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - ulong.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + ulong.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out ulong result) => #if NET8_0_OR_GREATER ulong.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - ulong.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - ulong.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + ulong.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out ulong result) => #if NET8_0_OR_GREATER ulong.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - ulong.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - ulong.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + ulong.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif /// diff --git a/src/Polyfill/Numbers/UShortPolyfill.cs b/src/Polyfill/Numbers/UShortPolyfill.cs index 67e8a859..313f1758 100644 --- a/src/Polyfill/Numbers/UShortPolyfill.cs +++ b/src/Polyfill/Numbers/UShortPolyfill.cs @@ -35,10 +35,8 @@ public static bool TryParse(string? target, IFormatProvider? provider, out ushor public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider, out ushort result) => #if NET8_0_OR_GREATER ushort.TryParse(target, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - ushort.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #else - ushort.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, provider, out result); + ushort.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, provider, out result); #endif /// @@ -70,10 +68,8 @@ public static bool TryParse(ReadOnlySpan target, IFormatProvider? provider public static bool TryParse(ReadOnlySpan target, NumberStyles style, IFormatProvider? provider, out ushort result) => #if NET8_0_OR_GREATER ushort.TryParse(target, style, provider, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - ushort.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #else - ushort.TryParse(Encoding.UTF8.GetString(target.ToArray()), style, provider, out result); + ushort.TryParse(Encoding.UTF8.GetString(target), style, provider, out result); #endif /// @@ -83,10 +79,8 @@ public static bool TryParse(ReadOnlySpan target, NumberStyles style, IForm public static bool TryParse(ReadOnlySpan target, out ushort result) => #if NET8_0_OR_GREATER ushort.TryParse(target, out result); -#elif FeatureMemory && AllowUnsafeBlocks || NETCOREAPP2_1_OR_GREATER - ushort.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #else - ushort.TryParse(Encoding.UTF8.GetString(target.ToArray()), NumberStyles.Integer, null, out result); + ushort.TryParse(Encoding.UTF8.GetString(target), NumberStyles.Integer, null, out result); #endif ///