diff --git a/src/Polyfill/Polyfill_Encoding.cs b/src/Polyfill/Polyfill_Encoding.cs index d0d9a0e..a44f78e 100644 --- a/src/Polyfill/Polyfill_Encoding.cs +++ b/src/Polyfill/Polyfill_Encoding.cs @@ -45,10 +45,13 @@ public static unsafe int GetBytes(this Encoding target, ReadOnlySpan chars } } +#endif +#if !NETCOREAPP2_1_OR_GREATER /// When overridden in a derived class, decodes all the bytes in the specified byte span into a string. /// A read-only byte span to decode to a Unicode string. /// A string that contains the decoded bytes from the provided read-only span. //Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring#system-text-encoding-getstring(system-readonlyspan((system-byte))) +#if AllowUnsafeBlocks public static unsafe string GetString(this Encoding target, ReadOnlySpan bytes) { if (target is null) @@ -61,7 +64,18 @@ public static unsafe string GetString(this Encoding target, ReadOnlySpan b return target.GetString(bytesPtr, bytes.Length); } } +#else + public static string GetString(this Encoding target, ReadOnlySpan bytes) + { + if (target is null) + { + throw new ArgumentNullException(nameof(target)); + } + + return target.GetString(bytes.ToArray()); + } +#endif #endif } -#endif +#endif \ No newline at end of file