Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1380

Inheriting BsonDocument

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.0.1
    • Component/s: BSON

      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).

            Assignee:
            Unassigned Unassigned
            Reporter:
            pgordon@truckdown.com Peter Gordon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: