-
-
Save azkurban/74f45aa7305195c841fa4be44199aff8 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