SnowflakeGuid 0.1.2024.348

There is a newer version of this package available.
See the version list below for details.
dotnet add package SnowflakeGuid --version 0.1.2024.348                
NuGet\Install-Package SnowflakeGuid -Version 0.1.2024.348                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SnowflakeGuid" Version="0.1.2024.348" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SnowflakeGuid --version 0.1.2024.348                
#r "nuget: SnowflakeGuid, 0.1.2024.348"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SnowflakeGuid as a Cake Addin
#addin nuget:?package=SnowflakeGuid&version=0.1.2024.348

// Install SnowflakeGuid as a Cake Tool
#tool nuget:?package=SnowflakeGuid&version=0.1.2024.348                

Snowflake Guid Generator

This lib is a fork from SnowflakeIDGenerator. Most of this lib was developed by Fenase. See https://github.com/fenase/SnowflakeIDGenerator

Reason

SnowflakeID is a 64-bit number value. In dotnet this value can be represented by a ulong. However, when converting a ulong to a string, dotnet ends up rounding it and it tends to be filled with 3 zeros at the end. So you need to work with the conversion to string even if the value is a ulong.

ulong: 1864424336924868608
uuid: 8b7bbd43-d429-49c6-b64c-11586f994e75

Therefore, I created this lib to convert the ulong value to a uuid (Guid in dotnet).
You can either convert a uuid to snowflake and obtain its properties, or generate a snowflake and convert it to uuid.

I think it's more beautiful to see http://yourdomain.com/user/8b7bbd43-d429-49c6-b64c-11586f994e75 than http://yourdomain.com/user/1864424336924868608.

Usage

Usage - Generate


  Guid guid = SnowflakeGuidGenerator.GetGuid();

  //OR
  Snowflake snow = SnowflakeGuidGenerator.GetSnowflake();
  Guid guid = snow.Guid;

  //OR
  Guid guid = SnowflakeGuidGenerator.GetSnowflake().Guid;

  //OR ... you can put it on you object class
  public Guid id { get; private set; } = SnowflakeGuidGenerator.GetSnowflake().Guid;

Usage - Get Guid by SnowflakeID (Parse from ulong)

ulong value = 1864424336924868608;
Guid guid = new Snowflake(value);

Usage - Get Guid by SnowflakeID (Parse from string (ulong valid))

string value = "01864424336924868608";
Guid guid = new Snowflake(value);

Usage - Get SnowflakeID by Guid (Parse from a common Guid)

Guid value = Guid.Parse("8b7bbd43-d429-49c6-b64c-11586f994e75");
Snowflake snow = new Snowflake(value);

Usage - Properties of SnowflakeID

Snowflake snow = new Snowflake(guid);
Console.WriteLine(snow.UtcDateTime);  // 13/9/2022 22:27:47
Console.WriteLine(snow.Timestamp);    // 1663108067853
Console.WriteLine(snow.MachineId);    // 701
Console.WriteLine(snow.Sequence);     // 3911
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net20 is compatible.  net35 is compatible.  net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 2.0

    • No dependencies.
  • .NETFramework 3.5

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 1.3

  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.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.

Version Downloads Last updated
1.0.2 107 12/16/2024
1.0.0 95 12/16/2024
0.1.2024.348 100 12/13/2024

# Changelog
## 1.5
- Slightly improved performance
- Improved documentation

## 1.4
- Added dependency injection helpers using Microsoft.Extensions.DependencyInjection.
 - To avoid package dependency bloating, this was added to package SnowflakeIDGenerator.DependencyInjection
- Added class SnowflakeIdGeneratorOptions to Microsoft.Extensions.DependencyInjection to help with automatic initialization from configuration.

## 1.3.2023
- Solved an issue that caused the custom epoch sometimes not being saved to the snowflake object. This does not affects the generated codes, but could make them to return the wrong date when parsed
- Comparisons should be between snowflakes using the same epoch
- Equality comparer returns false if the snowflakes being compared use different epochs

## 1.2.2023
- Added ability to change and rebase epoch to an already generated code
- Added implicit casting from Snowflake to string and ulong
- Added explicit casting to Snowflake from string and ulong

## 1.1.2023
- Added ability to use a custom epoch

## 1.0.2023
- Throw exception if time moves backwards

## 1.0.2022
- Initial version