public static ToBsonValue ( object value ) : BsonValue | ||
value | object | |
return | BsonValue |
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)); } } }
public void Add(object key, object value) { if (key == null) { throw new ArgumentNullException("key"); } _document.Add(key.ToString(), Actor.ToBsonValue(value)); }
public void Add(string key, object value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _document.Add(key, Actor.ToBsonValue(value)); }
void IDictionary.Add(object key, object value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _document.Add(key.ToString(), Actor.ToBsonValue(value)); }
public object this[int index] { get { return(Actor.ToObject(_array[index])); } set { _array[index] = Actor.ToBsonValue(value); } }
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)); } }
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)); } }
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)); } } }
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)); } }
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)); } } }
public bool TryMapToBsonValue(object value, out BsonValue bsonValue) { bsonValue = Actor.ToBsonValue(value); return(true); }
public void Insert(int index, object value) { _array.Insert(index, Actor.ToBsonValue(value)); }
public int IndexOf(object value) { return(_array.IndexOf(Actor.ToBsonValue(value))); }
public void Remove(object value) { _array.Remove(Actor.ToBsonValue(value)); }
// PS friendly Add public void Add(object value) { _array.Add(Actor.ToBsonValue(value)); }
public int Add(object value) { _array.Add(Actor.ToBsonValue(value)); return(_array.Count - 1); }
public bool Contains(object value) { return(_array.Contains(Actor.ToBsonValue(value))); }
void ICollection <KeyValuePair <string, object> > .Add(KeyValuePair <string, object> item) { _document.Add(item.Key, Actor.ToBsonValue(item.Value)); }