QKP.EzId
2.1.1
dotnet add package QKP.EzId --version 2.1.1
NuGet\Install-Package QKP.EzId -Version 2.1.1
<PackageReference Include="QKP.EzId" Version="2.1.1" />
<PackageVersion Include="QKP.EzId" Version="2.1.1" />
<PackageReference Include="QKP.EzId" />
paket add QKP.EzId --version 2.1.1
#r "nuget: QKP.EzId, 2.1.1"
#:package QKP.EzId@2.1.1
#addin nuget:?package=QKP.EzId&version=2.1.1
#tool nuget:?package=QKP.EzId&version=2.1.1
EzId
EzId is a lightweight .NET library for generating unique, sortable, and human-friendly readable identifiers (using Crockford Base32 encoding). It supports both 96-bit (inspired on MongoDB's ObjectID ) and 64-bit ID formats ( inspired by Twitter Snowflake ) and provides source generators for custom strongly-typed IDs with customization support for separators.
96-bit IDs: each process uses a random generated 40-bit generatorID and a 24-bit sequence (random start incrementing per ID). This approach makes coordination unnecessary, with collision odds negligible across distributed systems.
64-bit IDs: require manually assigning unique generator IDs (0–1023) for each concurrent process to avoid collisions. Each generator can emit up to 4,096 IDs per millisecond.
Example IDs:
- 96-bit:
070AB-47XF6Q8NH0-YPA40
(22 chars, dash separators) - 96-bit:
070AB_47XF6Q8NH0_YPA40
(22 chars, underscore separators) - 96-bit:
070AB47XF6Q8NH0YPA40
(20 chars, no separators) - 64-bit:
070-47XF6Q8-YPA
(15 chars, dash separators) - 64-bit:
070_47XF6Q8_YPA
(15 chars, underscore separators) - 64-bit:
07047XF6Q8YPA
(13 chars, no separators)
Installation
dotnet add package QKP.EzId
For source generation support (recommended):
dotnet add package QKP.EzId.SourceGenerator
Usage
EzId ( 96-bit ID )
using QKP.EzId;
EzId id = EzId.GetNextId();
string idString = id.ToString(); // e.g. "070AB-47XF6Q8NH0-YPA40"
EzId parsedId = EzId.Parse(idString);
CompactEzId ( 64-bit ID )
using QKP.EzId;
// Create a CompactEzIdGenerator with a unique generator ID (0-1023)
var generator = new CompactEzIdGenerator<CompactEzId>(generatorId: 1);
// Generate a new ID
CompactEzId id = generator.GetNextId();
// Convert to string
string idString = id.ToString(); // e.g. "070-47XF6Q8-YP0"
// Parse from string
CompactEzId parsedId = CompactEzId.Parse(idString);
Source Generated Custom ID Types
You can create your own strongly-typed IDs using the source generator. Annotate a partial struct with [EzIdType]
or customize with constructor arguments:
using QKP.EzId;
// Default: 96-bit, dash separators at positions [5, 15]
// eg. XXXXX-XXXXXXXXXX-XXXXX
[EzIdType]
public partial struct ProductId { }
// Custom: 96-bit, dash separators at positions [2, 18]
// eg. XX-XXXXXXXXXXXXXXXX-XX
[EzIdType(IdBitSize.Bits96, SeparatorOptions.Dash, [2, 18])]
public partial struct PriceId { }
// Custom 64-bit, underscore separators at positions [3, 10]
// eg. XXX_XXXXXXX_XXX
[EzIdType(IdBitSize.Bits64, SeparatorOptions.Underscore, [3, 10])]
public partial struct SessionId { }
// Custom 64-bit, no separators (64-bit)
// eg. XXXXXXXXXXXXX
[EzIdType(IdBitSize.Bits64, SeparatorOptions.None, [])]
public partial struct UserId { }
Usage
var productId = ProductId.Generate();
string productId = id.ToString(); // eg. "070AB-47XF6Q8NH0-YPA40"
SessionId parsedProductId = ProductId.Parse(productId);
var generator = new CompactEzIdGenerator<SessionId>(generatorId: 1);
SessionId sessionId = generator.GetNextId();
string sessionIdString = id.ToString(); // eg. "070_47XF6Q8_YP0"
SessionId parsedSessionId = SessionId.Parse(sessionIdString);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 is compatible. 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- System.Text.Json (>= 9.0.7)
-
net8.0
- System.Text.Json (>= 9.0.7)
-
net9.0
- System.Text.Json (>= 9.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on QKP.EzId:
Package | Downloads |
---|---|
QKP.EzId.SourceGenerator
Source generator for QKP.EzId that enables creation of custom ID types. |
GitHub repositories
This package is not used by any popular GitHub repositories.