md.shortguid
2.0.1
dotnet add package md.shortguid --version 2.0.1
NuGet\Install-Package md.shortguid -Version 2.0.1
<PackageReference Include="md.shortguid" Version="2.0.1" />
<PackageVersion Include="md.shortguid" Version="2.0.1" />
<PackageReference Include="md.shortguid" />
paket add md.shortguid --version 2.0.1
#r "nuget: md.shortguid, 2.0.1"
#:package md.shortguid@2.0.1
#addin nuget:?package=md.shortguid&version=2.0.1
#tool nuget:?package=md.shortguid&version=2.0.1
Short Guid
PM> NuGet\Install-Package md.shortguid
A V4 GUID represented in the form of a short(er), base64-encoded, url-safe, string.
With the option to replace version, and variant data for custom flags.
By default .net's Guid.NewGuid(), creates a Version "4", and Variant "DCE 1.1, ISO/IEC 11578:1996" UUID.
ShortGuid replaces these constant values with custom ones, allowing users to set flags in these locations.
A standard Guid has 36 characters: 2249d2d9-e29a-4c7c-9505-256760d13fad.
A ShortGuid has 22 characters: 2dJJIprifEyVBSVnYNE_rQ.
Guids, and ShortGuids can be converted to one another without any data loss.
ShortGuids are url safe.
Short Guid
var sg1 = new ShortGuid(); // Creates a new ShortGuid, generating a new Guid.
var sg2 = new ShortGuid(Guid.NewGuid()); // Creates a ShortGuid, from an existing Guid.
var sg3 = ShortGuid.NewGuid(); // Same as the empty constructor, aligns with Guid's api.
Short Guid With Flags
// Int32 type flags, in the range of 0 - 63 (inclusive), allows for 64 unique values.
var flags = 63;
var sg1 = new ShortGuid(flags);
// As an alternative, enums can be used with up to 64 unique fields.
public enum Values
{
A = 0,
B = 1,
...
Y = 62,
Z = 63
}
var valueFlags = Values.Z;
var sg2 = new ShortGuid<Values>(valueFlags);
// You could use a flags enum with up to 7 combined values.
[Flags]
public enum Flags
{
A = 0,
B = 1,
C = 2,
D = 4,
E = 8,
F = 16,
G = 32
}
var combinedFlags = Flags.A | Flags.B | Flags.C | Flags.D | Flags.E | Flags.F | Flags.G;
var sg3 = new ShortGuid<Flags>(combinedFlags);
Converting between Guids and Short Guids
// This example uses the provided extension methods, but it can be done though the ShortGuid type as well.
Guid guidIn = Guid.NewGuid(); // e.g. "6a54c832-f9c5-4fc5-bdd2-c546fb513499".
int flagsIn = 42;
// Guid to ShortGuid:
string shortGuid = guidIn.ToShortGuid(flagsIn); // e.g. "MshUasX5xa_90sVG_1E0mQ".
// ShortGuid to Guid:
var (guidOut, flagsOut) = shortGuid.ToGuid();
// ShortGuid contains both the original guid, and flags data; while being 2/3 of the size (when comparing the string formats).
Assert.Equal(guidIn, guidOut);
Assert.Equal(flagsIn, flagsOut);
Version 7 Guid
All the same functionality as the Version 4 Guid, along with the ability to extract the datetime component.
var state = 42;
var now = DateTimeOffset.UtcNow;
var shortGuid1 = ShortGuid.CreateVersion7(now, state); // Create V7 Guid with params.
var shortGuid2 = ShortGuid.CreateVersion7(shortGuid1.Value); // Reconstruct the ShortGuid from the value: "AxSfASdL2KOIsU99dR4SbQ".
(Guid guid, int flags, DateTimeOffset? timestamp, string value) = shortGuid2; // Extract the components from a ShortGuid.
// guid: 019f1403-4b27-73d8-88b1-4f7d751e126d
// flags: 42
// timestamp: 29/06/2026 3:33:08 PM +00:00
// value: AxSfASdL2KOIsU99dR4SbQ
var areEqual = shortGuid1.Guid == shortGuid2.Guid; // True.
areEqual = shortGuid1.Flags == shortGuid2.Flags; // True.
areEqual = shortGuid1.Timestamp == shortGuid2.Timestamp; // True.
areEqual = shortGuid1.Value == shortGuid2.Value; // True.
areEqual = shortGuid1 == shortGuid2; // True.
Credits
- Icon made by Vitaly Gorbachev from Flaticon
- Guid Diagram Example from uuidtools.
Changelog
1.0.0
ShortGuidtype, with the options of using a plain V4 GUID, or one with custom flags.
2.0.0
- Updated framework to dotnet 10.
- Added support for V7 Guids.
2.0.1
- Added datetime extraction from V7 guids.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
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.
## 2.0.1
* Added datetime extraction from V7 guids.