CardinalityEstimation icon indicating copy to clipboard operation
CardinalityEstimation copied to clipboard

Add .NET Standard 2.0 build support

Open onyxmaster opened this issue 7 months ago • 0 comments

Hi!

Thank you for building this library. Unfortunately, currently it cannot be used with legacy runtimes like .NET Framework. But since this library does not use many "new" .NET-specific features, adding support for .NET Standard 2.0 (and thus supporting .NET Framework 4.6.2 and later) is quite easy. The proposed changes include the following:

  • add netstandard2.0 TFM along with allowing latest language version so the default language version limiter does not kick in
  • use System.Numerics.BitOperations.LeadingZeroCount(ulong) instead of ulong.LeadingZeroCount(ulong) (same functionality, different names) since it's easier to polyfill + polyfilling it with relatively quick implementation that is only used for .NET Standard 2.0
  • use BitConverter.ToUint64 overload that specifies the target index, because only it is available in .NET Standard 2.0 (there is no performance degradation for the "main" case of .NET 8+9, I ran the benchmarks to verify it)
  • add IEnumerable<>.ToHashSet<> polyfill for .NET Standard 2.0

With these changes, most of the library remains unmodified, the added files are only built for the new TFM and the performance of the existing code is unchanged, but the library can be used by many more developers, who cannot right now target modern versions of .NET for compatibility reasons.

Thanks for taking a look.

onyxmaster avatar Sep 21 '25 20:09 onyxmaster