doekman
doekman

Reputation: 19288

Is there a way to ensure no implicit culture settings are used?

I have some classes which can't make assumptions about de used culture. These classes should always use CultureInfo.InvariantCulture. However, I can't set the thread's current culture to CultureInfo.InvariantCulture, because other classes rely on <globalization culture="auto".

Is there a way to ensure some classes always use explicit culture method calls (like: Convert.ToDecimal(value, CultureInfo.InvariantCulture)) instead of assumed culture (like: Convert.ToDecimal(value)).

Maybe my question it's not 100% clear: I'd like to detect all methods which have an overload which uses CultureInfo, but also one without the CultureInfo which uses the CurrentCulture.

This includes implicit casts of numbers to string:

decimal value = 1.0;
string displayThis = string.Format("Costs: {0}", value);

The goal is to make sure some classes/methods don't assume anything about CultureInfo.

Supposedly I should solve this with FxCop. Any tips on this?

Upvotes: 2

Views: 190

Answers (2)

Kris Ivanov
Kris Ivanov

Reputation: 10598

you can use Convert.ToDecimal Method (Object, IFormatProvider) and pass your culture specific provider

Upvotes: 1

Henk Holterman
Henk Holterman

Reputation: 273464

No, but you could easily roll your own ConertInvariant.ToDecimal(...) wrappers.

Upvotes: 1

Related Questions