Ian Boyd
Ian Boyd

Reputation: 256999

How to get the culture of an IFormatProvider

i am converting strings to values using a culture specified to me as a IFormatProvider.

i am trying to figure out which culture they gave me.

i realize that IFormatProvider doesn't necessarily have to correspond to a System.Globalization.Culture, but it did.

So how can i get its name?

Upvotes: 2

Views: 1997

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039348

The CultureInfo class implements IFormatProvider so you may try casting:

IFormatProvider provider = ...
CultureInfo ci = provider as CultureInfo;
if (ci != null)
{
    string name = ci.DisplayName;
    ...
}

Upvotes: 6

Related Questions