Exemple #1
0
        public static FriendlyId64?Parse([NotNull] string str)
        {
            var parts = str.Split('-');

            if (parts.Length != 4)
            {
                return(null);
            }

            var ab = parts[0];

            if (ab.Length != 6)
            {
                return(null);
            }
            var cd = parts[1];

            if (cd.Length != 6)
            {
                return(null);
            }
            var ef = parts[2];

            if (ef.Length != 6)
            {
                return(null);
            }
            var gh = parts[3];

            if (gh.Length != 6)
            {
                return(null);
            }

            var abcd = FriendlyId32.Parse($"{ab}-{cd}");
            var efgh = FriendlyId32.Parse($"{ef}-{gh}");

            if (!abcd.HasValue || !efgh.HasValue)
            {
                return(null);
            }

            var value = ((ulong)abcd.Value.Value << 32) | efgh.Value.Value;

            unchecked
            {
                value *= MultiplyInverse;
                value -= Offset;
            }

            return(new FriendlyId64(value));
        }
Exemple #2
0
        [NotNull] public override string ToString()
        {
            var number = Value;

            unchecked
            {
                number += Offset;
                number *= Multiply;
            }

            unsafe
            {
                var ints = new Span <uint>(&number, 2);

                var n1 = ints[0];
                var n2 = ints[1];

                var abcd = new FriendlyId32(n1);
                var efgh = new FriendlyId32(n2);

                return($"{efgh}-{abcd}");
            }
        }