Can you think of a reason why creating a new class that inherits from BsonDocument would not work?
if I create this class:
public class GenericEntity : BsonDocument { public GenericEntity() : base() { } public GenericEntity(Dictionary<string, object> dictionary) : base(dictionary) { } public GenericEntity(IEnumerable<KeyValuePair<string, object>> dictionary) : base(dictionary) { } public GenericEntity(IDictionary dictionary) : base(dictionary) { } public GenericEntity(IEnumerable<BsonElement> elements) : base(elements) { } public GenericEntity(BsonElement element) : base(element) { } public GenericEntity(bool allowDuplicateNames) : base(allowDuplicateNames) { } public GenericEntity(string name, BsonValue value) : base(name, value) { } }
and then run this code:
var test = new Generic(); test.Add(new BsonElement("name", "test")); test.Add(new BsonElement("db", "testdb")); Console.Write(test.ToString());
if returns "{[{ }, { }]}" instead of the expcted "test3 = {{ "name" : "test", "db" : "testdb" }}" even though the Elements property appears to be populated properly (two elemnts each with the name an dvalue fields set properly).