Created
June 28, 2017 14:04
-
-
Save sacarino/a7869b8ef4917c75623a35fb74243cc2 to your computer and use it in GitHub Desktop.
C# - Generate a GUID from an ObjectID
This file contains hidden or 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; | |
using System.Linq; | |
using MongoDB.Bson; | |
namespace Extensions | |
{ | |
internal static class BsonToGuid | |
{ | |
internal static Guid AsGuid(this BsonObjectId oid) | |
{ | |
var bytes = oid.Value.ToByteArray().Concat(new byte[] { 5, 5, 5, 5 }).ToArray(); | |
Guid gid = new Guid(bytes); | |
return gid; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why 5s?