Skip to content

Instantly share code, notes, and snippets.

@timoteoramos
Created February 16, 2017 19:05
Show Gist options
  • Save timoteoramos/8c22a206258454993409348530344235 to your computer and use it in GitHub Desktop.
Save timoteoramos/8c22a206258454993409348530344235 to your computer and use it in GitHub Desktop.
.NET GUID Utils
using System;
public static class GuidUtils
{
public static Guid FromInt64(params long[] f)
{
byte[] result = new byte[16];
BitConverter.GetBytes (f [0]).CopyTo (result, 0);
BitConverter.GetBytes (f [1]).CopyTo (result, 8);
return new Guid (result);
}
public static long[] ToInt64(Guid f)
{
byte[] dump = f.ToByteArray ();
long[] result = new long[2];
result [0] = BitConverter.ToInt64 (new byte[] {
dump [0],
dump [1],
dump [2],
dump [3],
dump [4],
dump [5],
dump [6],
dump [7]
}, 0);
result [1] = BitConverter.ToInt64 (new byte[] {
dump [8],
dump [9],
dump [10],
dump [11],
dump [12],
dump [13],
dump [14],
dump [15]
}, 0);
return result;
}
}
@franksantos
Copy link

Muito bom timoteo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment