Skip to content

Commit

Permalink
Handle endianess in SequentialGuidGenerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
anpete committed Feb 14, 2014
1 parent 7c15786 commit 641e488
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ public class SequentialGuidIdentityGenerator : IIdentityGenerator<Guid>

static SequentialGuidIdentityGenerator()
{
_counter = DateTime.Now.Ticks;
_counter = DateTime.UtcNow.Ticks;
}

public Task<Guid> NextAsync()
{
var guidBytes = Guid.NewGuid().ToByteArray();
var counterBytes = BitConverter.GetBytes(Interlocked.Increment(ref _counter));

if (!BitConverter.IsLittleEndian)
{
Array.Reverse(counterBytes);
}

guidBytes[08] = counterBytes[1];
guidBytes[09] = counterBytes[0];
guidBytes[10] = counterBytes[7];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlServer
public class SequentialGuidIdentityGeneratorTest
{
[Fact]
public async Task Can_get_next_values()
public async Task CanGetNextValues()
{
var sequentialGuidIdentityGenerator = new SequentialGuidIdentityGenerator();
var values = new List<Guid>();
Expand Down

0 comments on commit 641e488

Please sign in to comment.