Created
February 16, 2017 19:05
-
-
Save timoteoramos/8c22a206258454993409348530344235 to your computer and use it in GitHub Desktop.
.NET GUID Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muito bom timoteo