ToBsonValue() public static method

public static ToBsonValue ( object value ) : BsonValue
value object
return BsonValue
示例#1
0
        public Dictionary(object value)
        {
            if (Environment.GetEnvironmentVariable("MdbcDictionaryLegacy") == "0")
            {
                throw new InvalidOperationException("Used deprecated Mdbc.Dictionary(object)");
            }

            value = Actor.BaseObject(value);
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value is Dictionary that)
            {
                _document = (BsonDocument)that._document.DeepClone();
            }
            else
            {
                var bson = Actor.ToBsonValue(value);
                if (bson.BsonType == BsonType.Document)
                {
                    _document = bson.AsBsonDocument;
                }
                else
                {
                    _document = new BsonDocument(BsonId.Element(bson));
                }
            }
        }
示例#2
0
 public void Add(object key, object value)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     _document.Add(key.ToString(), Actor.ToBsonValue(value));
 }
示例#3
0
 public void Add(string key, object value)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     _document.Add(key, Actor.ToBsonValue(value));
 }
示例#4
0
 void IDictionary.Add(object key, object value)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     _document.Add(key.ToString(), Actor.ToBsonValue(value));
 }
示例#5
0
 public object this[int index]
 {
     get
     {
         return(Actor.ToObject(_array[index]));
     }
     set
     {
         _array[index] = Actor.ToBsonValue(value);
     }
 }
示例#6
0
 public object this[string key]
 {
     get
     {
         if (key == null)
         {
             throw new ArgumentNullException(nameof(key));
         }
         return(_document.TryGetValue(key, out BsonValue value) ? Actor.ToObject(value) : null);
     }
     set
     {
         if (key == null)
         {
             throw new ArgumentNullException(nameof(key));
         }
         _document.Set(key, Actor.ToBsonValue(value));
     }
 }
示例#7
0
 object IDictionary.this[object key]
 {
     get
     {
         if (key == null)
         {
             throw new ArgumentNullException(nameof(key));
         }
         return(_document.TryGetValue(key.ToString(), out BsonValue value) ? Actor.ToObject(value) : null);
     }
     set
     {
         if (key == null)
         {
             throw new ArgumentNullException(nameof(key));
         }
         _document.Set(key.ToString(), Actor.ToBsonValue(value));
     }
 }
示例#8
0
        public Collection(ICollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (collection is Collection that)
            {
                _array = (BsonArray)that._array.DeepClone();
            }
            else
            {
                _array = new BsonArray(collection.Count);
                foreach (var item in collection)
                {
                    _array.Add(Actor.ToBsonValue(item));
                }
            }
        }
示例#9
0
 public object this[object key]
 {
     get
     {
         if (key == null)
         {
             throw new ArgumentNullException("key");
         }
         BsonValue value;
         return(_document.TryGetValue(key.ToString(), out value) ? Actor.ToObject(value) : null);
     }
     set
     {
         if (key == null)
         {
             throw new ArgumentNullException("key");
         }
         _document.Set(key.ToString(), Actor.ToBsonValue(value));
     }
 }
示例#10
0
        public Collection(object value)
        {
            value = Actor.BaseObject(value);
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value is IEnumerable en && !(value is string))
            {
                if (en is Collection that)
                {
                    _array = (BsonArray)that._array.DeepClone();
                }
                else
                {
                    _array = new BsonArray();
                    foreach (var item in en)
                    {
                        _array.Add(Actor.ToBsonValue(item));
                    }
                }
            }
示例#11
0
 public bool TryMapToBsonValue(object value, out BsonValue bsonValue)
 {
     bsonValue = Actor.ToBsonValue(value);
     return(true);
 }
示例#12
0
 public void Insert(int index, object value)
 {
     _array.Insert(index, Actor.ToBsonValue(value));
 }
示例#13
0
 public int IndexOf(object value)
 {
     return(_array.IndexOf(Actor.ToBsonValue(value)));
 }
示例#14
0
 public void Remove(object value)
 {
     _array.Remove(Actor.ToBsonValue(value));
 }
示例#15
0
 // PS friendly Add
 public void Add(object value)
 {
     _array.Add(Actor.ToBsonValue(value));
 }
示例#16
0
 public int Add(object value)
 {
     _array.Add(Actor.ToBsonValue(value));
     return(_array.Count - 1);
 }
示例#17
0
 public bool Contains(object value)
 {
     return(_array.Contains(Actor.ToBsonValue(value)));
 }
示例#18
0
 void ICollection <KeyValuePair <string, object> > .Add(KeyValuePair <string, object> item)
 {
     _document.Add(item.Key, Actor.ToBsonValue(item.Value));
 }