MongoDB.Bson.Serialization.Serializers.BsonDocumentSerializer.GetDocumentId C# (CSharp) Метод

GetDocumentId() публичный метод

Gets the document Id.
public GetDocumentId ( object document, object &id, Type &idNominalType, IIdGenerator &idGenerator ) : bool
document object The document.
id object The Id.
idNominalType System.Type The nominal type of the Id.
idGenerator IIdGenerator The IdGenerator for the Id type.
Результат bool
        public bool GetDocumentId(
            object document,
            out object id,
            out Type idNominalType,
            out IIdGenerator idGenerator)
        {
            var bsonDocument = (BsonDocument)document;

            BsonElement idElement;
            if (bsonDocument.TryGetElement("_id", out idElement))
            {
                id = idElement.Value;
                idGenerator = BsonSerializer.LookupIdGenerator(id.GetType());

                if (idGenerator == null)
                {
                    var idBinaryData = id as BsonBinaryData;
                    if (idBinaryData != null && (idBinaryData.SubType == BsonBinarySubType.UuidLegacy || idBinaryData.SubType == BsonBinarySubType.UuidStandard))
                    {
                        idGenerator = BsonBinaryDataGuidGenerator.GetInstance(idBinaryData.GuidRepresentation);
                    }
                }
            }
            else
            {
                id = null;
                idGenerator = BsonObjectIdGenerator.Instance;
            }

            idNominalType = typeof(BsonValue);
            return true;
        }