Irrelevant.Hasher
3.2.0
dotnet add package Irrelevant.Hasher --version 3.2.0
NuGet\Install-Package Irrelevant.Hasher -Version 3.2.0
<PackageReference Include="Irrelevant.Hasher" Version="3.2.0" />
<PackageVersion Include="Irrelevant.Hasher" Version="3.2.0" />
<PackageReference Include="Irrelevant.Hasher" />
paket add Irrelevant.Hasher --version 3.2.0
#r "nuget: Irrelevant.Hasher, 3.2.0"
#:package Irrelevant.Hasher@3.2.0
#addin nuget:?package=Irrelevant.Hasher&version=3.2.0
#tool nuget:?package=Irrelevant.Hasher&version=3.2.0
Hasher
Simple Hashing helper for entities. Default behaviour calculates the HashCode for all public properties.
HasherIncludeAttribute can be used to include non-public ones.
HasherExcludeAttribute can be used to exclude public ones.
Usage
Normal
using Irrelevant.Hasher;
public class Entity
{
public int Property1 { get; set; }
public int Property2 { set => Console.Write(value); } // Skipped
private int Property3 { get; set; } // Skipped
[HasherInclude] private int Property4 { get; set; }
[HasherExclude] public int Property5 { get; set; } // Skipped
}
var entity = new Entity();
var hashCode = entity.ResolveHash();
Async
using Irrelevant.Hasher;
public class EntityWithTasks
{
public Task<int> Property1 { get; set; } // Will await this value
public int Property2 { set => Console.Write(value); } // Skipped
private int Property3 { get; set; } // Skipped
[HasherInclude] private int Property4 { get; set; }
[HasherExclude] public int Property5 { get; set; } // Skipped
}
var entity = new EntityWithTasks();
var hashCode = await entity.ResolveHashAsync();
By using ResolveHashAsync we will get the HashCode of the actual Task value, if any, instead of the Task's HashCode.
Null
Returns 0 for null values.
using Irrelevant.Hasher;
string nullString = null;
var hashCode = nullString.ResolveHash(); // == 0
Nested vs Top Level Only
Starting version 2.0, nested hashes are possible. By default, this is disabled. To enable it, set HasherFactory.CalculatedNestedHashes to true.
In version 3.0, the factory was removed and the process was refactored to work as a service. You can enable nested calculations during registration using:
serviceCollection.AddHasher(o => o.EnableNestedHashes());
Custom Mappings
Starting version 2.0, custom mappings are allowed for certain types. This can be done by registering your customized set of values using HasherFactory.Register<T> or HasherFactory.RegisterAsync<T>.
A silly little example, but showing the power quite well:
HasherFactory.Register<string>(x => x.Length, x => x.Count(s => s == 's'), x => x.Count(s => s == 'd'));
You can unregister again using HasherFactory.UnRegister<T> and HasherFactory.UnRegisterAsync<T> .
In version 3.0, the factory was removed and the process was refactored to work as a service. You can configure your mappings using:
serviceCollection.AddHasher(o => o.Register<string>(x => x.Length, x => x.Count(s => s == 's'), x => x.Count(s => s == 'd'))
.Register<Entity>(x => x.Property1, x => x.Property2));
This, obviously, only works when using the injected service (IHashService). Simpler mapping has been supplied for the extension methods by using the HasherConfiguration attribute which offers support for top level property names:
[HasherConfiguration(nameof(MyProperty1), nameof(MyProperty3))]
public class MyClass3
{
public int MyProperty1 { get; set; }
public int MyProperty2 { get; set; } // Skipped
public int MyProperty3 { get; set; }
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
-
net5.0
-
net6.0
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 |
|---|