ModernBCL.Core.HashCode 1.0.0

Suggested Alternatives

ModernBCL.Core.BLC

Additional Details

Migrate to ModernBCL.Core.BLC, improve performance and implement more features.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ModernBCL.Core.HashCode --version 1.0.0
                    
NuGet\Install-Package ModernBCL.Core.HashCode -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ModernBCL.Core.HashCode" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ModernBCL.Core.HashCode" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ModernBCL.Core.HashCode" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ModernBCL.Core.HashCode --version 1.0.0
                    
#r "nuget: ModernBCL.Core.HashCode, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ModernBCL.Core.HashCode@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ModernBCL.Core.HashCode&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ModernBCL.Core.HashCode&version=1.0.0
                    
Install as a Cake Tool

ModernBCL.Core.HashCode

A high-performance polyfill for the System.HashCode struct, backported to .NET Framework 4.8. This library enables developers to efficiently implement the required GetHashCode() method for custom types used in Dictionary and other hash-based collections, overcoming a key feature gap in the legacy BCL.

🚀 Motivation

The modern System.HashCode struct (introduced in .NET Core) provides a fast, non-allocating, and, most importantly, order-sensitive way to combine multiple fields into a single hash code. Without it, developers on .NET 4.8 must write complex, manual bit-mixing code, which is often error-prone and leads to hash collisions.

This package provides a drop-in solution to ensure your custom dictionary keys maintain high performance and correctness in legacy applications.

✨ Features

Order Sensitivity: Generates a different hash for (A, B) versus (B, A).

Performance: Uses optimized bitwise operations (rotations, XORs) for fast calculation.

Non-Allocating: Designed as a struct to avoid heap allocations.

Simple API: Provides clean static Combine helpers up to 8 arguments.

📦 Installation

Install the package via NuGet:

.NET CLI

dotnet add package ModernBCL.Core.HashCode

Package Manager Console

Install-Package ModernBCL.Core.HashCode

💻 Usage

Once installed, use the static HashCode.Combine method inside your custom class's GetHashCode() override.

Example: ProductKey.cs

using System; // Note: HashCode is available automatically in the System namespace

public class ProductKey { public string ProductId { get; } public string Color { get; } public int Size { get; } // ... constructor and Equals implementation omitted for brevity

public override int GetHashCode()
{
    // One clean line replaces dozens of manual mixing operations.
    return HashCode.Combine(ProductId, Color, Size);
}

}

🤝 Contribution

Contributions are welcome! If you find a bug or want to suggest a performance improvement for the underlying hashing algorithm, please open an issue or submit a pull request on GitHub.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET Framework net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated