-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGuidGenerator.cs
39 lines (30 loc) · 993 Bytes
/
GuidGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
//using System.Security.Cryptography;
namespace NFive.SDK.Core.Helpers
{
public static class GuidGenerator
{
/// <summary>
/// Generates a time based globally unique identifier optimized for MySQL.
/// </summary>
/// <returns>The generated GUID.</returns>
public static Guid GenerateTimeBasedGuid()
{
//var randomBytes = new byte[10];
//using (var rng = RandomNumberGenerator.Create()) rng.GetBytes(randomBytes);
//var timestampBytes = BitConverter.GetBytes(DateTime.UtcNow.Ticks / 10000L);
//if (BitConverter.IsLittleEndian) Array.Reverse(timestampBytes);
//var guidBytes = new byte[16];
//Buffer.BlockCopy(timestampBytes, 2, guidBytes, 0, 6);
//Buffer.BlockCopy(randomBytes, 0, guidBytes, 6, 10);
//// ReSharper disable once InvertIf
//if (BitConverter.IsLittleEndian)
//{
// Array.Reverse(guidBytes, 0, 4);
// Array.Reverse(guidBytes, 4, 2);
//}
//return new Guid(guidBytes);
return Guid.NewGuid();
}
}
}