[CSHARP-558] Replace AsXyz and ToXyz in BsonValue with GetXyz in BsonDocument Created: 07/Sep/12  Updated: 17/Apr/14  Resolved: 17/Apr/14

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 1.6
Fix Version/s: 2.0

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-563 Add indexing to BsonValue Closed
is related to CSHARP-560 Remove explicit conversions from Bson... Closed
Backwards Compatibility: Major Change

 Description   

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");



 Comments   
Comment by Robert Stam [ 17/Apr/14 ]

We have decided not to do this since it would be a backward compatibility breaking change.

Comment by Robert Stam [ 09/Sep/12 ]

Linking to CSHARP-563, which seems like a better improvement to the API than this one.

Generated at Wed Feb 07 21:37:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.