PseudoGuid 1.1.0
dotnet add package PseudoGuid --version 1.1.0
NuGet\Install-Package PseudoGuid -Version 1.1.0
<PackageReference Include="PseudoGuid" Version="1.1.0" />
<PackageVersion Include="PseudoGuid" Version="1.1.0" />
<PackageReference Include="PseudoGuid" />
paket add PseudoGuid --version 1.1.0
#r "nuget: PseudoGuid, 1.1.0"
#:package PseudoGuid@1.1.0
#addin nuget:?package=PseudoGuid&version=1.1.0
#tool nuget:?package=PseudoGuid&version=1.1.0
Pseudo Guid
Summary
Generate identifiers, conforming to the Guid CLR type, that are based on a prefix and sequence.
The identifiers are not compliant with RFC4122 (and are marked with a version outside of what is defined in RFC4122 / RFC9562,
as to guarantee never colliding with an actually compliant UUID, such as one generated using Guid.NewGuid).
Targets netstandard2.0 and net10.0 (the latter is allocation-free and trimming/AOT compatible).
Prefixes
Identifier prefixes are based on an Enum type. Each enum value's name is hashed (MD5 by default) to generate a prefix.
The prefix is 12 bytes long when the sequence is 4 bytes (int, uint), and 8 bytes long when the sequence is 8 bytes (long, ulong).
In the event that the Enum type being used results in a potential prefix collision, a PseudoGuidException is thrown.
Because prefixes come from names, renaming an enum member changes its identifiers. Enums with aliased members (two names for the same value) are rejected.
Usage
// Construct once and reuse; instances are immutable and thread-safe.
var pgs = new PseudoGuids<Color, int>();
Guid id = pgs.Encode(Color.Red, 1);
// Decode, discovering the kind
if (pgs.TryDecode(id, out var kind, out var seq)) { /* kind == Color.Red, seq == 1 */ }
var (k, s) = pgs.Decode(id); // throws ArgumentException if not a pseudo-guid
// Decode, requiring a specific kind (e.g. an API route that only accepts Red ids)
if (pgs.TryDecode(id, Color.Red, out var redSeq)) { /* ... */ }
int redSeq2 = pgs.Decode(id, Color.Red);
pgs.IsPseudoGuid(Guid.NewGuid()); // false
A custom hash algorithm can be supplied via new PseudoGuids<Color, int>(new KindHashes<Color>(hashAlgorithm)).
The algorithm is only used during construction and is not disposed.
Compatibility
The wire format is stable: identifiers produced by 1.0.x decode identically with later versions (covered by golden-value tests). Sequences are stored little-endian.
| 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 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 is compatible. 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.Memory (>= 4.6.3)
-
net10.0
- 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.
Removed dynamic / Microsoft.CSharp dependency; added net10.0 target with allocation-free encode/decode; added default MD5 constructors, Decode, IsPseudoGuid and kind-checked TryDecode; clearer errors for undefined and aliased enum values.