ChatGptNet icon indicating copy to clipboard operation
ChatGptNet copied to clipboard

Guid.CreateVersion7()

Open N1K0232 opened this issue 9 months ago • 5 comments

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

N1K0232 avatar Apr 29 '25 16:04 N1K0232

Which methods are you referring to?

marcominerva avatar Apr 29 '25 16:04 marcominerva

I mean something like:

#if NET_8_OR_LOWER return Guid.NewGuid(); #else return Guid.CreateVersion7();

N1K0232 avatar Apr 29 '25 18:04 N1K0232

OK... But where in the code?

marcominerva avatar Apr 29 '25 19:04 marcominerva

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();
}

}

N1K0232 avatar Apr 30 '25 12:04 N1K0232

I don't see any value in using this solution, because in this case we're not dealing with things like index fragmentation.

marcominerva avatar Apr 30 '25 12:04 marcominerva