GuidSupplement 1.0.1
dotnet add package GuidSupplement --version 1.0.1
NuGet\Install-Package GuidSupplement -Version 1.0.1
<PackageReference Include="GuidSupplement" Version="1.0.1" />
<PackageVersion Include="GuidSupplement" Version="1.0.1" />
<PackageReference Include="GuidSupplement" />
paket add GuidSupplement --version 1.0.1
#r "nuget: GuidSupplement, 1.0.1"
#:package GuidSupplement@1.0.1
#addin nuget:?package=GuidSupplement&version=1.0.1
#tool nuget:?package=GuidSupplement&version=1.0.1
GuidSupplement
Starting with .NET 9, Guid has added functionality compliant with UUID Version 7. However, these features are not available in older .NET environments (e.g., .NET Standard 2.0), so GuidSupplement provides nearly equivalent functionality for these platforms. You can install package from NuGet/GuidSupplement.
Table of Contents
Target Runtime
.NET Standard 2.0, .NET Standard 2.1, .NET 8, .NET 9, .NET 10
GuidVersion7 class
Create method
Creates a Guid compliant with UUID v7.
For target runtimes below .NET 9, it executes processing equivalent to the Guid.CreateVersion7 method.
For .NET 9 and above, it executes the Guid.CreateVersion7 method directly.
var guid = GuidVersion7.Create();
var guid = GuidVersion7.Create(DateTimeOffset.UtcNow);
IsVersion7 method
Returns true if the Guid is compliant with UUID v7. Returns false otherwise.
var guid = GuidVersion7.Create();
if (GuidVersion7.IsVersion7(id))
{
Console.WriteLine("Id is UUID version 7");
}
GetTimestamp method
Retrieves the timestamp. Throws an exception if the Guid is not compliant with UUID v7.
var id = GuidVersion7.Create();
DateTimeOffset timestamp = GuidVersion7.GetTimestamp(id);
GetUnixTimeSeconds method
Retrieves the timestamp as Unix epoch milliseconds. Throws an exception if the Guid is not compliant with UUID v7.
var id = GuidVersion7.Create();
long timestamp = GuidVersion7.GetUnixTimeSeconds(id);
TimestampComparer property
var ids = new List<Guid>();
ids.Add(GuidVersion7.Create(new DateTimeOffset(2025, 10, 17, 23, 49, 0, TimeSpan.Zero)));
ids.Add(GuidVersion7.Create(new DateTimeOffset(2025, 10, 17, 23, 49, 1, TimeSpan.Zero)));
ids.Add(GuidVersion7.Create(new DateTimeOffset(2025, 10, 17, 23, 49, 2, TimeSpan.Zero)));
ids.Add(GuidVersion7.Create(new DateTimeOffset(2025, 10, 17, 23, 49, 3, TimeSpan.Zero)));
var shuffled = ids.OrderBy(_ => Guid.NewGuid()).ToList();
shuffled.Sort(GuidVersion7.TimestampComparer);
GuidExtensions
Some features added in .NET 8 and .NET 9 can be used in older .NET environments.
Guid.TryWriteBytes method
var id = new Guid("00112233-4455-6677-8899-aabbccddeeff");
Span<byte> value = stackalloc byte[16];
id.TryWriteBytes(value);
// [51, 34, 17, 0, 85, 68, 119, 102, 136, 153, 170, 187, 204, 221, 238, 255]
Guid.ToByteArray(bool bigEndian) method
var id = new Guid("00112233-4455-6677-8899-aabbccddeeff");
var bytes = id.ToByteArray(false);
// [51, 34, 17, 0, 85, 68, 119, 102, 136, 153, 170, 187, 204, 221, 238, 255]
Guid.GetVersion method
Performs the same operation as the Guid.Version property.
var id = Guid.NewGuid();
var version = id.GetVersion(); // 4
var id = GuidVersion7.Create();
var version = id.GetVersion(); // 7
Guid.GetVariant method
Performs the same operation as the Guid.Variant property.
var id = Guid.NewGuid();
var variant = id.GetVariant();
var id = GuidVersion7.Create();
var variant = id.GetVariant();
License
MIT License. Some code is implemented based on dotnet/runtime, Please check the original license.
| 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 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 is compatible. |
| .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
- Microsoft.Bcl.Memory (>= 9.0.9)
- System.Buffers (>= 4.6.1)
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
.NETStandard 2.1
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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.