diff --git a/src/Persistence/GuidV7.cs b/src/Persistence/GuidV7.cs index 93f4f257f..aad89783c 100644 --- a/src/Persistence/GuidV7.cs +++ b/src/Persistence/GuidV7.cs @@ -1,4 +1,4 @@ -// +// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // @@ -14,8 +14,16 @@ namespace MUnique.OpenMU.Persistence; /// public static class GuidV7 { + /// + /// Creates a new random guid. + /// + /// The new guid. public static Guid NewGuid() => NewGuid(DateTimeOffset.UtcNow); + /// + /// Creates a new random guid for the specified date. + /// + /// The new guid. public static Guid NewGuid(DateTimeOffset dateTimeOffset) { // We create a buffer which is two bytes bigger than the Guid, @@ -23,7 +31,7 @@ public static Guid NewGuid(DateTimeOffset dateTimeOffset) Span buffer = stackalloc byte[18]; var uuidAsBytes = buffer[2..]; var currentTimestamp = dateTimeOffset.ToUnixTimeMilliseconds(); - Span timestampBytes = stackalloc byte[sizeof(long)]; + if (!BitConverter.TryWriteBytes(buffer, currentTimestamp)) { throw new InvalidOperationException("Could not convert the timestamp to bytes.");