示例#1
0
        /// <summary>
        /// Returns value from root document (used in parameter). Returns same document if name are empty
        /// </summary>
        public static BsonValue PARAMETER_PATH(BsonDocument doc, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(doc);
            }

            if (doc.TryGetValue(name, out BsonValue item))
            {
                return(item);
            }
            else
            {
                return(BsonValue.Null);
            }
        }
示例#2
0
 private void DeserializeObject(EntityMapper entity, object obj, BsonDocument value)
 {
     foreach (var member in entity.Members.Where(x => x.Setter != null))
     {
         if (value.TryGetValue(member.FieldName, out var val))
         {
             // check if has a custom deserialize function
             if (member.Deserialize != null)
             {
                 member.Setter(obj, member.Deserialize(val, this));
             }
             else
             {
                 member.Setter(obj, this.Deserialize(member.DataType, val));
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Remove document _id if contains a "empty" value (checks for autoId bson type)
        /// </summary>
        private bool RemoveDocId(BsonDocument doc)
        {
            if (doc.TryGetValue("_id", out var id))
            {
                // check if exists _autoId and current id is "empty"
                if ((_autoId == BsonAutoId.Int32 && (id.IsInt32 && id.AsInt32 == 0)) ||
                    (_autoId == BsonAutoId.ObjectId && (id.IsNull || (id.IsObjectId && id.AsObjectId == ObjectId.Empty))) ||
                    (_autoId == BsonAutoId.Guid && id.IsGuid && id.AsGuid == Guid.Empty) ||
                    (_autoId == BsonAutoId.Int64 && id.IsInt64 && id.AsInt64 == 0))
                {
                    // in this cases, remove _id and set new value after
                    doc.Remove("_id");
                    return(true);
                }
            }

            return(false);
        }