[CSHARP-762] BsonValue .ToString() should have an overload that accepts CultureInfo Created: 21/Jun/13  Updated: 20/Mar/14  Resolved: 14/Aug/13

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

Type: Bug Priority: Trivial - P5
Reporter: Clifford Hammerschmidt Assignee: Sridhar Nanjundeswaran
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File bsondocumenttostringerror.png     PNG File bsondocumenttostringrsharp.png    

 Description   

See attached screen caps.

Basically:

var s = bsonValue.ToString(CultureInfo.InvariantCulture);

should be allowed, and should propagate the CultureInfo to any ToString calls made to sub-objects stringified in the process of rendering the string.



 Comments   
Comment by Sridhar Nanjundeswaran [ 13/Aug/13 ]

Additionally if you do have a use case that does need to produce culture dependent values you could use the overloads from the actual value type which can be obtained using <bsonval>.value. e.g.

var bsonInt = new BsonInt32(1000);
var str1 = bsonInt.ToString();   <--- Invariant string
var str2 = bsonInt.Value.ToString("C", new CultureInfo("en-us").NumberFormat);    <---- Culture dependent formatting to currency

Comment by Robert Stam [ 27/Jun/13 ]

All BsonValue subtypes already override ToString to produce values that are not culture dependent. All BsonValue ToString results are either based on XmlConvert or on custom implementations of ToString.

Since the values are already not culture dependent, there doesn't seem to be a need for calling ToString with CultureInfo.Invariant. Is there a use case for an overload of ToString that produces culture dependent values?

Comment by Robert Stam [ 27/Jun/13 ]

The type of the parameter should probably be IFormatProvider, not CultureInfo.

Comment by Clifford Hammerschmidt [ 21/Jun/13 ]

That's the only place I've seen it.

Comment by Craig Wilson [ 21/Jun/13 ]

Thanks for the report. I've assigned this for a fix in 1.9. I'm sure there are a number of other places care might need to be given to culture. Have you noticed anywhere else?

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