[CSHARP-129] Static BsonTypeMapper function to cast from BsonValue to native types Created: 07/Dec/10  Updated: 02/Apr/15  Resolved: 20/Jan/11

Status: Closed
Project: C# Driver
Component/s: Feature Request
Affects Version/s: 0.9
Fix Version/s: 0.11

Type: Improvement Priority: Major - P3
Reporter: J W Lee Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Attachments: Text File bsontypemapper.txt    
Backwards Compatibility: Fully Compatible

 Description   

Is it possible to incorporate a static function to map BsonValues back to .NET types? The current conversion is one way only.
This will open up avenues for developers writing generic classes that accept types (e.g. strongly typed generic cache manager class using MongoDb as the store)

I have attached an implementation in the BsonTypeMapper class I have been testing with my code. The implementation uses the type mapping declared in the private dictionaries.



 Comments   
Comment by Robert Stam [ 20/Jan/11 ]

BsonValue now implements IConvertible.

Comment by Craig Wilson [ 28/Dec/10 ]

Could BsonValue (or it's implementors) simply implement IConvertible? That way it is synonymous with the core types, int, long, bool, etc...

Comment by J W Lee [ 07/Dec/10 ]

I have added another static function to determine if a type has a Conversion mapping to a Bson type.

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