Modern Polyfills for Legacy .NET Framework 4.8 / 4.8.1
ModernBCL.Core.BLC brings high-performance, zero-allocation replacements for missing modern BCL APIs to legacy .NET Framework apps — enabling performance and clarity normally available only in .NET 7/8.
This library is especially useful for:
- Enterprise systems that must stay on .NET Framework 4.8 / 4.8.1
- Developers wanting modern C# coding patterns on legacy frameworks
- Teams needing high-quality hashing or safe guard clauses
- Projects migrating from .NET Framework → .NET Core but needing parity
- Drop-in System.HashCode polyfill (for .NET Framework only)
- Modern, order-sensitive
HashCode.Combine() HashAccumulator(32-bit) andHashAccumulator64(64-bit)- Extremely low collision rates
- Zero allocations
- Clean replacement for repetitive null/empty/whitespace checks
- Fluent
Guard.Against()API - Polyfilled
[CallerArgumentExpression]attribute - No need to manually pass parameter names
- Modern BCL patterns for older frameworks
- Full parity with .NET 6/7/8 guard & hashing behavior (where appropriate)
Install via NuGet:
.NET CLI
dotnet add package ModernBCL.Core.BLC --version 1.2.0Visual Studio Package Manager Console
Install-Package ModernBCL.Core.BLC -Version 1.2.0| Target | Status | Notes |
|---|---|---|
| .NET Framework 4.8 / 4.8.1 | ✔ Supported | HashCode polyfill is active |
| .NET 8+ / .NET Core | ✔ Supported | Uses native System.HashCode (polyfill disabled) |
| NuGet Package | ✔ Multi-target | net48; net481; net8.0 |
ModernBCL intelligently switches behavior:
- Under net48/net481 → uses ModernBCL HashCode polyfill
- Under net8+ → uses native framework HashCode
using System;
public class ProductKey
{
public string ProductId { get; }
public string Color { get; }
public int Size { get; }
public override int GetHashCode()
{
return HashCode.Combine(ProductId, Color, Size);
}
}using ModernBCL.Core.Guards;
public class DependencyContainer
{
public DependencyContainer(object service, string clientName)
{
_service = Guard.Against(service).Null();
_clientName = Guard.Against(clientName).NullOrWhiteSpace();
}
}- Only used under .NET Framework
- Fully deterministic
- Zero allocations
- Based on
HashAccumulator
- Provides
[CallerArgumentExpression]for .NET Framework - Modern fluent API on legacy runtimes
Benchmark results generated to:
BenchmarkDotNet.Artifacts/results/
Formats:
.html.md.csv
✔ Added multi-targeting: net48; net481; net8.0
✔ Added HashAccumulator64 (64-bit hashing)
✔ Added comparer suite
✔ Added full Guard API
✔ Added fuzz tests
✔ Added benchmarks
✔ Improved HashCode polyfill
✔ Support for both net48 and net481
✔ ThrowHelper + polyfill attributes
✔ Initial release with HashCode polyfill
MIT License.