Last active
November 8, 2016 18:45
-
-
Save Sinstraliz/b95d2f8b69cbba658b3e to your computer and use it in GitHub Desktop.
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
public static class GuidIntConverter | |
{ | |
public static Guid ToGuid(int integer) | |
{ | |
return new GuidConverter(integer).Guid; | |
} | |
public static int ToInt(Guid guid) | |
{ | |
return new GuidConverter(guid).Integer; | |
} | |
[StructLayout(LayoutKind.Explicit)] | |
private struct GuidConverter | |
{ | |
public GuidConverter(int integer) | |
: this() | |
{ | |
Integer = integer; | |
} | |
public GuidConverter(Guid guid) | |
: this() | |
{ | |
Guid = guid; | |
} | |
[FieldOffset(0)] | |
public readonly int Integer; | |
[FieldOffset(0)] | |
public readonly Guid Guid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment