A static class that maps between .NET objects and BsonValues.
예제 #1
0
        /// <summary>
        /// Adds elements to the document from a dictionary of key/value pairs.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <returns>The document (so method calls can be chained).</returns>
        public virtual BsonDocument AddRange(IEnumerable <KeyValuePair <string, object> > dictionary)
        {
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            foreach (var entry in dictionary)
            {
                Add(entry.Key, BsonTypeMapper.MapToBsonValue(entry.Value));
            }

            return(this);
        }
예제 #2
0
        /// <summary>
        /// Adds multiple elements to the array.
        /// </summary>
        /// <param name="values">A list of values to add to the array.</param>
        /// <returns>The array (so method calls can be chained).</returns>
        public virtual BsonArray AddRange(IEnumerable values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            foreach (var value in values)
            {
                Add(BsonTypeMapper.MapToBsonValue(value));
            }

            return(this);
        }
예제 #3
0
 /// <summary>
 /// Adds elements to the document from a dictionary of key/value pairs.
 /// </summary>
 /// <param name="dictionary">The dictionary.</param>
 /// <returns>The document (so method calls can be chained).</returns>
 public BsonDocument AddRange(IDictionary dictionary)
 {
     if (dictionary != null)
     {
         foreach (DictionaryEntry entry in dictionary)
         {
             if (entry.Key.GetType() != typeof(string))
             {
                 throw new ArgumentOutOfRangeException("One or more keys in the dictionary passed to BsonDocument.AddRange is not a string.");
             }
             Add((string)entry.Key, BsonTypeMapper.MapToBsonValue(entry.Value));
         }
     }
     return(this);
 }
예제 #4
0
 public BsonDocument Add(IDictionary <string, object> dictionary, IEnumerable <string> keys)
 {
     if (keys == null)
     {
         throw new ArgumentNullException("keys");
     }
     if (dictionary != null)
     {
         foreach (var key in keys)
         {
             Add(key, BsonTypeMapper.MapToBsonValue(dictionary[key]));
         }
     }
     return(this);
 }
예제 #5
0
 public BsonDocument Add(IDictionary dictionary, IEnumerable keys)
 {
     if (keys == null)
     {
         throw new ArgumentNullException("keys");
     }
     if (dictionary != null)
     {
         foreach (var key in keys)
         {
             if (key.GetType() != typeof(string))
             {
                 throw new ArgumentOutOfRangeException("A key passed to BsonDocument.Add is not a string.");
             }
             Add((string)key, BsonTypeMapper.MapToBsonValue(dictionary[key]));
         }
     }
     return(this);
 }