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

Replace AsXyz and ToXyz in BsonValue with GetXyz in BsonDocument

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • 2.0
    • Affects Version/s: 1.6
    • Component/s: BSON
    • None
    • None
    • Major Change
    • None
    • None
    • None
    • None
    • None
    • None

      The AsXyz and ToXyz methods and properties in BsonValue have the problem that because they are declared in BsonValue you can call any of them all of the time even if there is no chance they will succeed. The shear number of them also clutter up Intellisense.

      These methods and properties exist because the only accessor in BsonDocument returns values of type BsonValue, so you need these methods and properties to work with the resulting BsonValue.

      However, a better way is to have a family of GetXyz methods in BsonDocument that return different types as appropriate, so since the return value is already of the desired type no further AsXyz or ToXyz methods or properties are needed.

      For example, the old way:

      var pages = document["pages"].AsInt32;
      

      the new way:

      var pages = document.GetInt32("pages");
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: