### Install UUIDNext.Cli via NuGet Source: https://github.com/mareek/uuidnext/blob/main/Src/UUIDNext.Cli/README.md Install the tool globally using the .NET CLI. ```text dotnet tool install --global UUIDNext.Cli ``` -------------------------------- ### Method: Compare(Guid, Guid) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.guidcomparer.md Compares two Guid instances and returns an integer indicating their relative sort order. ```APIDOC ## Compare(Guid, Guid) ### Description Compares two Guids and returns an indication of their relative sort order. ### Parameters - **x** (Guid) - Required - The first Guid to compare. - **y** (Guid) - Required - The second Guid to compare. ### Returns - **Int32** - A signed integer that indicates the relative values of x and y: less than zero if x is less than y, zero if x equals y, or greater than zero if x is greater than y. ``` -------------------------------- ### GetVersion Method Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md Retrieves the version of a given Guid. ```csharp public static int GetVersion(Guid guid) ``` -------------------------------- ### Convert GUID to byte array Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.guidhelper.md Returns an unsigned byte array representation of the provided Guid. ```csharp public static Byte[] ToByteArray(Guid guid, bool bigEndian) ``` -------------------------------- ### GuidHelper Methods Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.guidhelper.md Utility methods for converting GUIDs to byte representations and vice versa. ```APIDOC ## FromBytes(Span, Boolean) ### Description Creates a new Guid from a span of bytes. ### Parameters - **bytes** (Span) - Required - The span of bytes to convert. - **bigEndian** (Boolean) - Required - Specifies if the byte order is big-endian. ### Returns - **Guid** - The resulting Guid. ## ToByteArray(Guid, Boolean) ### Description Returns an unsigned byte array containing the GUID. ### Parameters - **guid** (Guid) - Required - The Guid to convert. - **bigEndian** (Boolean) - Required - Specifies if the byte order should be big-endian. ### Returns - **Byte[]** - The byte array representation of the Guid. ## TryWriteBytes(Guid, Span, Boolean, Int32) ### Description Returns whether bytes are successfully written to the given span. ### Parameters - **guid** (Guid) - Required - The Guid to write. - **bytes** (Span) - Required - The destination span. - **bigEndian** (Boolean) - Required - Specifies if the byte order should be big-endian. - **bytesWritten** (Int32) - Required - The number of bytes written to the span. ### Returns - **Boolean** - True if the operation was successful, otherwise false. ``` -------------------------------- ### Compare Guids Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.guidcomparer.md Compares two Guids and returns an indication of their relative sort order. This method is part of the IComparer interface. ```csharp public int Compare(Guid x, Guid y) ``` -------------------------------- ### Create GUID from bytes Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.guidhelper.md Creates a new Guid instance from a span of bytes with specified endianness. ```csharp public static Guid FromBytes(Span bytes, bool bigEndian) ``` -------------------------------- ### NewNameBased(Guid, String) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a new UUID Version 5 based on a namespace and a name. ```APIDOC ## NewNameBased(Guid, String) ### Description Create a new UUID Version 5. ### Method POST ### Endpoint /api/uuid/newNameBased ### Parameters #### Query Parameters - **namespaceId** (Guid) - Required - The name space ID - **name** (String) - Required - The name from which to generate the UUID ### Response #### Success Response (200) - **uuid** (Guid) - The newly generated UUID ### Response Example ```json { "uuid": "f0e1d2c3-b4a5-6789-0123-456789abcdef" } ``` ``` -------------------------------- ### GetVersion(Guid) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md Retrieves the version number of a given UUID. ```APIDOC ## GetVersion(Guid) ### Description Returns the version of the UUID. ### Parameters #### Path Parameters - **guid** (Guid) - Required - The UUID to inspect. ### Response #### Success Response (200) - **Returns** (Int32) - The version number of the UUID. ``` -------------------------------- ### Write GUID to span Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.guidhelper.md Attempts to write the Guid bytes into the provided span, returning success status and the number of bytes written. ```csharp public static bool TryWriteBytes(Guid guid, Span bytes, bool bigEndian, out int bytesWritten) ``` -------------------------------- ### TryDecodeSequence(Guid, Int16) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md Attempts to extract the sequence component from UUID versions 1, 6, 7, or 8 (if sequential). ```APIDOC ## TryDecodeSequence(Guid, Int16) ### Description Try to retrieve the sequence part of a UUID v1, v6, v7 or V8 (if the UUIDv8 is a sequential UUID for SQL Server). ### Parameters #### Path Parameters - **guid** (Guid) - Required - The UUID to decode. - **sequence** (Int16) - Required - The output parameter to store the decoded sequence. ### Response #### Success Response (200) - **Returns** (Boolean) - True if the sequence was successfully decoded, otherwise false. ``` -------------------------------- ### TryDecodeTimestamp(Guid, DateTime) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md Attempts to extract the timestamp from UUID versions 1, 6, 7, or 8 (if sequential). ```APIDOC ## TryDecodeTimestamp(Guid, DateTime) ### Description Try to retrieve the date part of a UUID v1, v6, v7 or V8 (if the UUIDv8 is a sequential UUID for SQL Server). ### Parameters #### Path Parameters - **guid** (Guid) - Required - The UUID to decode. - **date** (DateTime) - Required - The output parameter to store the decoded date. ### Response #### Success Response (200) - **Returns** (Boolean) - True if the timestamp was successfully decoded, otherwise false. ``` -------------------------------- ### UUIDNext.Cli Command Reference Source: https://github.com/mareek/uuidnext/blob/main/Src/UUIDNext.Cli/README.md Overview of available commands and options for the CLI tool. ```text Description : Generate a new UUID Usage : uuidnext command [options] [--clipboard] Commands : Random Create a new UUID v4 Sequential Create a new UUID v7 Database [dbName] Create a UUID to be used as a database primary key (v7 or v8 depending on the database) dbName can be "PostgreSQL", "SqlServer", "SQLite" or "Other" Decode [UUID] Decode the versioo of the UUID and optionally the timestamp an sequence number of UUID v1, 6, 7 and 8 Version Show the version --clipboard : copy output to clipboard ``` -------------------------------- ### GuidComparer Constructor Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.guidcomparer.md Initializes a new instance of the GuidComparer class. ```csharp public GuidComparer() ``` -------------------------------- ### Generate Database-Friendly and Name-Based UUIDs in C# Source: https://github.com/mareek/uuidnext/blob/main/README.md Demonstrates creating database-specific sequential UUIDs and name-based UUIDs using the Uuid class. ```C# using System; using UUIDNext; // Creating a database friendly UUID for PostgreSQL (version 7) or MS SQL Server (Version 8) Guid postgreSqlUuid = Uuid.NewDatabaseFriendly(Database.PostgreSql); Console.WriteLine($"This is a PostgreSQL friendly UUID : {postgreSqlUuid}"); Guid sqlServerUuid = Uuid.NewDatabaseFriendly(Database.SqlServer); Console.WriteLine($"This is a SQL Server friendly UUID : {sqlServerUuid}"); // Creating a name based UUID (Version 5) Guid nameBasedUuid = Uuid.NewNameBased(Uuid.Namespace.URL, "https://github.com/uuid6/uuid6-ietf-draft"); Console.WriteLine($"This is a name based UUID : {nameBasedUuid}"); ``` -------------------------------- ### Create UUID v7 with Timestamp and Following Bytes Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Creates a UUID version 7 with a specified Unix epoch timestamp in milliseconds and a Span of bytes. The remaining bits are filled with random data. Note that version and variant bits will be overwritten. ```csharp public static Guid CreateUuidV7(long timestamp, Span followingBytes) ``` -------------------------------- ### NewSequential() Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a new UUID Version 7, which is a sequential UUID. ```APIDOC ## NewSequential() ### Description Create a new UUID Version 7. ### Method GET ### Endpoint /api/uuid/newSequential ### Response #### Success Response (200) - **uuid** (Guid) - The newly generated sequential UUID ### Response Example ```json { "uuid": "123e4567-e89b-12d3-a456-426614174000" } ``` ``` -------------------------------- ### Generate Sequential UUID (Version 7) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a new Version 7 sequential UUID. ```csharp public static Guid NewSequential() ``` -------------------------------- ### Generate and Decode UUIDs Source: https://github.com/mareek/uuidnext/blob/main/Src/UUIDNext.Cli/README.md Common commands for generating random, sequential, or database-specific UUIDs and decoding existing ones. ```bash # Creating a UUID Version 4 uuidnext random # Creating a UUID Version 7 uuidnext sequential # Creating a database friendly UUID for MS SQL Server (Version 8) uuidnext database sqlServer # Decoding version, timestamp and sequence from a UUID version 7 uuidnext decode 017F22E2-79B0-7CC3-98C4-DC0C0C07398F ``` -------------------------------- ### NewDatabaseFriendly(Database) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a new UUID that is best suited for storage in a database. ```APIDOC ## NewDatabaseFriendly(Database) ### Description Create a new UUID best suited for the selected database. ### Method GET ### Endpoint /api/uuid/newDatabaseFriendly ### Parameters #### Query Parameters - **database** (Database) - Required - The database where the UUID will be stored ### Response #### Success Response (200) - **uuid** (Guid) - The newly generated UUID ### Response Example ```json { "uuid": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### CreateSequentialUuidForSqlServerFromSpecificDate Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Generates a new sequential UUID optimized for SQL Server, using a specified date as the timestamp. ```APIDOC ## CreateSequentialUuidForSqlServerFromSpecificDate(DateTimeOffset) ### Description Create a new sequential UUID Optimised for SQL Server with the given date as timestamp. ### Method static ### Parameters #### Path Parameters - **date** (DateTimeOffset) - Required - The date to use for the timestamp. ### Returns Guid - A new sequential UUID optimized for SQL Server. ``` -------------------------------- ### Declare GuidComparer Class Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.guidcomparer.md Declares the GuidComparer class which inherits from System.Object and implements System.Collections.Generic.IComparer. ```csharp public class GuidComparer : System.Collections.Generic.IComparer ``` -------------------------------- ### TryDecodeSequence Method Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md Attempts to extract the sequence component from UUID versions 1, 6, 7, or specific sequential UUIDv8 variants. ```csharp public static bool TryDecodeSequence(Guid guid, out short sequence) ``` -------------------------------- ### Define Database Enumeration Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.database.md Represents the target database system for UUID storage. Use this to configure generation logic for specific database types. ```csharp public enum Database ``` -------------------------------- ### CreateUuidV7FromSpecificDate Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Generates a new UUID version 7 using a specified date as the timestamp. ```APIDOC ## CreateUuidV7FromSpecificDate(DateTimeOffset) ### Description Create a new UUID version 7 with the given date as timestamp. ### Method static ### Parameters #### Path Parameters - **date** (DateTimeOffset) - Required - The date to use for the timestamp. ### Returns Guid - A new UUID version 7. ``` -------------------------------- ### Database Enumeration Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.database.md Defines the target database system for UUID storage to ensure correct data type mapping. ```APIDOC ## Database Enumeration ### Description Specifies the target database system for UUID storage. This ensures that the generated UUID is formatted correctly for the specific database's native UUID or identifier type. ### Fields - **Other** (0) - Any other Database (MySQL, Oracle, MongoDB, etc.) - **SqlServer** (1) - Microsoft SQL Server (uniqueidentifier Type) - **SQLite** (2) - SQLite (BLOB or TEXT Type) - **PostgreSql** (3) - PostgreSQL (UUID Type) ``` -------------------------------- ### Create UUID v8 from Big-Endian Bytes Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Constructs a UUID version 8 using the provided bytes in big-endian order. The variant and version bits are automatically set. ```csharp public static Guid CreateGuidFromBigEndianBytes(Span bigEndianBytes) ``` -------------------------------- ### Generate Name-Based UUID (Version 5) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Generates a Version 5 UUID using a namespace ID and a name string. ```csharp public static Guid NewNameBased(Guid namespaceId, string name) ``` -------------------------------- ### Define UuidToolkit Class Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md This is the main class for UUID generation utilities. It contains static methods for creating different types of UUIDs. ```csharp public static class UuidToolkit ``` -------------------------------- ### CreateUuidV7(Int64, Span) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Creates a new UUID version 7 with a provided timestamp and a span of bytes, filling the remainder with random data. ```APIDOC ## CreateUuidV7(Int64, Span) ### Description Create a new UUID version 7 with the given timestamp and bytes of otherBytes, filling the rest with random data. ### Method static ### Parameters #### Path Parameters - **timestamp** (Int64) - Required - A unix epoch timestamp in ms. - **followingBytes** (Span) - Required - A series of 0 to 10 bytes used to fill the rest of the UUID. Be careful: some bits will be overxwritten by the version and variant of the UUID. ### Returns Guid - A UUID Version 7. ### Exceptions - ArgumentException ### Remarks Here is the bit layout of the UUID Version 7 created ``` 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | timestamp | ver | otherBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |var| otherBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | otherBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ``` ``` -------------------------------- ### Define GuidHelper class Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.guidhelper.md The static class definition for GuidHelper. ```csharp public static class GuidHelper ``` -------------------------------- ### Create Sequential UUID for SQL Server from Specific Date Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Generates a new sequential UUID optimized for SQL Server, using a provided DateTimeOffset as the timestamp. ```csharp public static Guid CreateSequentialUuidForSqlServerFromSpecificDate(DateTimeOffset date) ``` -------------------------------- ### Create Name-Based UUID v8 Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Generates a UUID version 8 based on a namespace ID and a name, using a specified hash algorithm (e.g., MD5, SHA-256) as per RFC section 6.5. ```csharp public static Guid CreateUuidFromName(Guid namespaceId, string name, HashAlgorithm hashAlgorithm) ``` -------------------------------- ### TryDecodeTimestamp Method Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md Attempts to extract the timestamp from UUID versions 1, 6, 7, or specific sequential UUIDv8 variants. ```csharp public static bool TryDecodeTimestamp(Guid guid, out DateTime date) ``` -------------------------------- ### CreateGuidFromBigEndianBytes Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Creates a new UUID version 8 from provided big-endian bytes, setting the variant and version bits. ```APIDOC ## CreateGuidFromBigEndianBytes(Span) ### Description Create new UUID version 8 with the provided bytes with the variant and version bits set. ### Method static ### Parameters #### Path Parameters - **bigEndianBytes** (Span) - Required - The bytes that will populate the UUID in big endian order. ### Returns Guid - A UUID version 8. ### Remarks Here is the bit layout of the UUID Version 8 created : ``` 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | bigEndianBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | bigEndianBytes | ver | bigEndianBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |var| bigEndianBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | bigEndianBytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ``` ``` -------------------------------- ### Create UUID v7 from Specific Date Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Generates a new UUID version 7 using a provided DateTimeOffset as the timestamp. Ensure the DateTimeOffset is in the correct format. ```csharp public static Guid CreateUuidV7FromSpecificDate(DateTimeOffset date) ``` -------------------------------- ### Generate Database-Friendly UUID Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a UUID optimized for the specified database type. ```csharp public static Guid NewDatabaseFriendly(Database database) ``` -------------------------------- ### Uuid Class Definition Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md The base static class for UUID generation. ```csharp public static class Uuid ``` -------------------------------- ### Generate Random UUID (Version 4) Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a new Version 4 random UUID. ```csharp public static Guid NewRandom() ``` -------------------------------- ### NewRandom() Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Creates a new UUID Version 4, which is a randomly generated UUID. ```APIDOC ## NewRandom() ### Description Create a new UUID Version 4. ### Method GET ### Endpoint /api/uuid/newRandom ### Response #### Success Response (200) - **uuid** (Guid) - The newly generated random UUID ### Response Example ```json { "uuid": "a1b2c3d4-e5f6-4789-8901-23456789abcd" } ``` ``` -------------------------------- ### Nil UUID Field Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Represents a UUID with all 128 bits set to zero. ```csharp public static Guid Nil; ``` -------------------------------- ### UuidDecoder Class Definition Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuiddecoder.md The static class definition for UuidDecoder. ```csharp public static class UuidDecoder ``` -------------------------------- ### CreateUuidFromName Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.tools.uuidtoolkit.md Generates a new name-based UUID version 8 according to RFC section 6.5. ```APIDOC ## CreateUuidFromName(Guid, String, HashAlgorithm) ### Description Create a new name based UUID version 8 according to section 6.5 of the RFC. ### Method static ### Parameters #### Path Parameters - **namespaceId** (Guid) - Required - The namespace where the name belongs. - **name** (String) - Required - The name to be hashed. - **hashAlgorithm** (HashAlgorithm) - Required - The hash algorithm used to compute the UUID (MD5, SHA-256, etc.). ### Returns Guid - A UUID version 8. ``` -------------------------------- ### Uuid Constants Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Provides access to special UUID constants: Max (all bits set to 1) and Nil (all bits set to 0). ```APIDOC ## Uuid Constants ### Description Provides access to special UUID constants: Max (all bits set to 1) and Nil (all bits set to 0). ### Fields #### **Max** The Max UUID is a special form of UUID that is specified to have all 128 bits set to 1. ```csharp public static Guid Max; ``` #### **Nil** The Nil UUID is a special form of UUID that is specified to have all 128 bits set to zero. ```csharp public static Guid Nil; ``` ``` -------------------------------- ### Max UUID Field Source: https://github.com/mareek/uuidnext/blob/main/Doc/uuidnext.uuid.md Represents a UUID with all 128 bits set to 1. ```csharp public static Guid Max; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.