Make C# driver deserialize Doubles and LongNumber(Int64) in MongoDocuments to Int32s (CSHARP-112)

[CSHARP-113] Add an attribute to allow you to be more or less strict about deserializing numeric bson types to numeric C# primative types Created: 23/Nov/10  Updated: 02/Apr/15  Resolved: 21/Jan/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 0.11

Type: Sub-task Priority: Minor - P4
Reporter: Justin Dearing Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The proposed attribute could be applied to numeric properties of classes that are deserialized from Bson Documents It shall allow you to become more strict or less strict about:
gaining precision
losing precision
gaining the ability to have a fractional part
losing a fractional part
going from float to decimal
going from decimal to float (if BSON is amended to allow a fixed point decimal)

I'll propose the name BsonNumericConversionAttribute, but I am open to a shorter name if it does not reduce the clarity of what it does.



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

Implemented the spirit of this request but differently. There is no need to have any options for conversions that don't lose data, and the only data losses that can occur are overflow and truncation (i.e. loss of precision). To control whether these types of losses are allowed or not I added the AllowOverflow and AllowTruncation properties to the RepresentationSerializationOptions and BsonRepresentationAttribute classes, so no new attribute was required.

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