Add BinaryPrimitives polyfills - #130
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a System.Buffers.Binary.BinaryPrimitives polyfill so consumers targeting .NET Framework, older .NET Standard, and older .NET Core can use the same BinaryPrimitives APIs (plus later-added byte/sbyte overloads) with accompanying tests and signature index updates.
Changes:
- Added a full
BinaryPrimitivestype polyfill for pre-.NET Core 2.1 / pre-.NET Standard 2.1 / .NET Framework targets. - Added Net50 “member polyfills” for
ReverseEndianness(byte)/ReverseEndianness(sbyte)(added in .NET 5). - Added a new NetCore21 test suite covering common read/write/try patterns and endianness correctness; updated signature inventory.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Signatures.md | Updates generated signature counts and adds BinaryPrimitives entries. |
| PolyShim/NetCore21/BinaryPrimitives.cs | New full polyfill implementation for BinaryPrimitives (reverse endianness + read/write + try APIs). |
| PolyShim/Net50/BinaryPrimitives.cs | Adds missing byte/sbyte ReverseEndianness members via member-polyfill extensions for pre-.NET 5 targets. |
| PolyShim.Tests/NetCore21/BinaryPrimitivesTests.cs | New tests for key endianness and try-read/write behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ator - Move byte/sbyte ReverseEndianness from Net50 to NetCore21 (introduced in .NET Core 2.1, not .NET 5.0) - Update signature generator to include methods from static class polyfills - All 72 BinaryPrimitives methods now correctly listed in Signatures.md as .NET Core 2.1 - Signatures count updated: Total 616 (+72), Members 502 (+72)
|
@copilot please regenerated the Signatures.md file, as I've merged in the latest |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #130 +/- ##
==========================================
+ Coverage 99.16% 99.19% +0.02%
==========================================
Files 147 148 +1
Lines 3846 3981 +135
Branches 87 87
==========================================
+ Hits 3814 3949 +135
Misses 13 13
Partials 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
System.Buffers.Binary.BinaryPrimitiveswas introduced in .NET Core 2.1 / .NET Standard 2.1 and is unavailable on .NET Framework, older .NET Standard, and .NET Core < 2.1. This adds full polyfill coverage.Changes
PolyShim/NetCore21/BinaryPrimitives.cs— Full static class polyfill active under(NETCOREAPP && !NETCOREAPP2_1_OR_GREATER) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) || NETFRAMEWORK:ReverseEndianness—short,ushort,int,uint,long,ulongReadXxx{Big,Little}Endian/TryReadXxx—Int16,UInt16,Int32,UInt32,Int64,UInt64,Single,DoubleWriteXxx{Big,Little}Endian/TryWriteXxx— same typesALLOW_UNSAFE_BLOCKSis defined; falls back toBitConverterotherwisePolyShim/Net50/BinaryPrimitives.cs— Extension methods forReverseEndianness(byte)andReverseEndianness(sbyte)added in .NET 5, covering the gap on netcoreapp2.1–3.x and netstandard2.1PolyShim.Tests/NetCore21/BinaryPrimitivesTests.cs— 39 tests covering read/write round-trips, endianness correctness, andTryXxxboundary checks