Guid.CreateVersion7()
With .NET 9, Guid struct obtained a new method called: CreateVersion7(). By using conditional compilation we can specify that on .NET 6, .NET 7 and .NET 8, only Guid.NewGuid() can be used, and from .NET 9 Guid.CreateVersion7() will be used
Which methods are you referring to?
I mean something like:
#if NET_8_OR_LOWER return Guid.NewGuid(); #else return Guid.CreateVersion7();
OK... But where in the code?
I apologise for not explaining myself properly yesterday.
The line of code I'm referring to is this one below: conversationId = (conversationId == Guid.Empty) ? Guid.NewGuid() : conversationId;
Which ensures that the conversationId won't be an Empty guid.
What I wanted to make was an internal static class like this:
internal static class GuidGenerator { internal static Guid NewGuid() { #if NET9 return Guid.CreateVersion7(); #endif
return Guid.NewGuid();
}
}
I don't see any value in using this solution, because in this case we're not dealing with things like index fragmentation.