Fix BinaryPrimitives float/double overloads missing when System.Memory is present - #133
Conversation
|
This is not the correct fix. The issue is that some of the methods were added in .NET 5 rather than .NET Core 2.1 (like the majority of them). Namely, the float/double overloads, but maybe not exclusively. These overloads are also not provided by the compatibilty packages. As such, they should be moved to the appropriate directory and have the appropriate guard attached to them. Please verify other methods too, make sure all guards are correct. Use Microsoft Docs for reference. |
Done in the latest commit. I verified against Microsoft Docs: the float/double overloads ( Changes:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #133 +/- ##
=======================================
Coverage 99.19% 99.19%
=======================================
Files 148 148
Lines 3981 3981
Branches 87 87
=======================================
Hits 3949 3949
Misses 13 13
Partials 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes missing BinaryPrimitives float/double read/write APIs on older TFMs when System.Memory is present by moving those APIs into a .NET 5–scoped polyfill layer, so they’re available on pre-.NET 5 targets without relying on System.Memory to provide them.
Changes:
- Move
ReadSingle*/ReadDouble*,WriteSingle*/WriteDouble*and correspondingTry*APIs out of the .NET Core 2.1 shim and into a .NET 5 shim implemented via static extension members. - Ensure the .NET 5 float/double APIs are compiled for all targets below .NET 5, and excluded on .NET 5+ where the APIs exist natively.
- Update
Signatures.mdto reflect that these overloads were introduced in .NET 5.0.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Signatures.md | Updates API introduction version annotations for BinaryPrimitives float/double overloads to .NET 5.0. |
| PolyShim/NetCore21/BinaryPrimitives.cs | Removes float/double overload implementations from the .NET Core 2.1 BinaryPrimitives shim. |
| PolyShim/Net50/BinaryPrimitives.cs | Adds .NET 5 float/double overloads (and Try* variants) via static extension members for pre-.NET 5 targets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot please update the PR description with an up-to-date overview of changes |
Updated. Here's the current overview: Changes
|
Changes
PolyShim/NetCore21/BinaryPrimitives.cs: Removed the 16 float/double overloads (ReadSingle*,ReadDouble*,WriteSingle*,WriteDouble*and theirTry*variants). The file now contains only integer methods and retains its original#if !FEATURE_MEMORYguard.PolyShim/Net50/BinaryPrimitives.cs(new): Adds the 16 float/double overloads via C# 14 static extension members (extension(BinaryPrimitives) { ... }), guarded by#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD). This augments System.Memory's integer-onlyBinaryPrimitivesclass on pre-.NET 5 targets rather than shadowing the entire class.Signatures.md: Updated the 16 float/double method entries from.NET Core 2.1to.NET 5.0.NetCore21/BinaryPrimitives.csNet50/BinaryPrimitives.cs