MapToBsonValue() public static method

Maps an object to a BsonValue.
public static MapToBsonValue ( object value ) : BsonValue
value object An object.
return BsonValue
Exemplo n.º 1
0
 /// <summary>
 /// Creates a new BsonArray.
 /// </summary>
 /// <param name="value">A value to be mapped to a BsonArray.</param>
 /// <returns>A BsonArray or null.</returns>
 public new static BsonArray Create(object value)
 {
     if (value != null)
     {
         return((BsonArray)BsonTypeMapper.MapToBsonValue(value, BsonType.Array));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new BsonTimestamp.
 /// </summary>
 /// <param name="value">An object to be mapped to a BsonTimestamp.</param>
 /// <returns>A BsonTimestamp or null.</returns>
 public new static BsonTimestamp Create(object value)
 {
     if (value != null)
     {
         return((BsonTimestamp)BsonTypeMapper.MapToBsonValue(value, BsonType.Timestamp));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 3
0
 // public static methods
 /// <summary>
 /// Creates a new BsonString.
 /// </summary>
 /// <param name="value">An object to be mapped to a BsonString.</param>
 /// <returns>A BsonString or null.</returns>
 public new static BsonString Create(object value)
 {
     if (value != null)
     {
         return((BsonString)BsonTypeMapper.MapToBsonValue(value, BsonType.String));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Returns one of the two possible BsonBoolean values.
 /// </summary>
 /// <param name="value">An object to be mapped to a BsonBoolean.</param>
 /// <returns>A BsonBoolean or null.</returns>
 public new static BsonBoolean Create(object value)
 {
     if (value != null)
     {
         return((BsonBoolean)BsonTypeMapper.MapToBsonValue(value, BsonType.Boolean));
     }
     else
     {
         return(null);
     }
 }
 // public methods
 /// <summary>
 /// Creates a new BsonRegularExpression.
 /// </summary>
 /// <param name="value">An object to be mapped to a BsonRegularExpression.</param>
 /// <returns>A BsonRegularExpression or null.</returns>
 public new static BsonRegularExpression Create(object value)
 {
     if (value != null)
     {
         return((BsonRegularExpression)BsonTypeMapper.MapToBsonValue(value, BsonType.RegularExpression));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new BsonJavaScript.
 /// </summary>
 /// <param name="value">An object to be mapped to a BsonJavaScript.</param>
 /// <returns>A BsonJavaScript or null.</returns>
 public new static BsonJavaScript Create(
     object value
     )
 {
     if (value != null)
     {
         return((BsonJavaScript)BsonTypeMapper.MapToBsonValue(value, BsonType.JavaScript));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new BsonBinaryData.
 /// </summary>
 /// <param name="value">An object to be mapped to a BsonBinaryData.</param>
 /// <returns>A BsonBinaryData or null.</returns>
 public new static BsonBinaryData Create(
     object value
     )
 {
     if (value != null)
     {
         return((BsonBinaryData)BsonTypeMapper.MapToBsonValue(value, BsonType.Binary));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new BsonDocument by mapping an object to a BsonDocument.
 /// </summary>
 /// <param name="value">The object to be mapped to a BsonDocument.</param>
 /// <returns>A BsonDocument.</returns>
 public new static BsonDocument Create(
     object value
     )
 {
     if (value != null)
     {
         return((BsonDocument)BsonTypeMapper.MapToBsonValue(value, BsonType.Document));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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);
 }