• This repository has been archived on 27/Mar/2024
  • Stars
    star
    125
  • Rank 285,250 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Universally Unique Lexicographically Sortable Identifier

Universally Unique Lexicographically Sortable Identifier

C# .NET Standard 2.0 port of alizain/ulid

CI Downloads

Usage

using System;
using CSharp.Ulid;

internal class Program
{
    private static void Main(string[] args)
    {
        Ulid ulidRandom = Ulid.NewUlid();

        Ulid ulidSpecific = new Ulid
        {
            TimeStamp_0 = 3,
            TimeStamp_1 = 4,
            TimeStamp_2 = 5,
            TimeStamp_3 = 6,
            TimeStamp_4 = 7,
            TimeStamp_5 = 8,
            Randomness_0 = 13,
            Randomness_1 = 14,
            Randomness_2 = 15,
            Randomness_3 = 16,
            Randomness_4 = 17,
            Randomness_5 = 18,
            Randomness_6 = 19,
            Randomness_7 = 20,
            Randomness_8 = 21,
            Randomness_9 = 22,
        };

        Ulid ulidFromLongBytes = new Ulid(123456L, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

        Ulid ulidFromBytesBytes = new Ulid(new byte[] { 0, 1, 2, 3, 4, 5 }, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

        Ulid ulidFromBytes = new Ulid(new byte[] { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

        Ulid ulidFromReadOnlySpan = new Ulid(new ReadOnlySpan<byte>(new byte[] { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));

        Ulid.TryParse("00000000000000000000000000", out Ulid ulitParsed);

        Ulid ulidDefault = default(Ulid);

        byte[] byteExplicit = (byte[])new Ulid();

        byte[] byteFromMethod = new Ulid().ToByteArray();

        Span<byte> storage = stackalloc byte[100];
        Span<byte> slicedSpan = storage.Slice(start: 55, length: 30);
        Ulid.NewUlid().TryWriteBytes(slicedSpan); // if true, we should get 16-bytes of Ulid bytes written in `storage` starting at index 55.

        string stringRepresentation = new Ulid().ToString();

    }
}

Prior Art