I would like to know how I can determine whether the CultureInfo instance returned by CultureInfo.CurrentCulture has all it's default values or whether it has been customised by the user.
I have done some testing using the following LINQPad snippet and the LINQPad command line runner.
var ci = CultureInfo.CurrentCulture;
var dtf = ci.DateTimeFormat;
ci.Name.Dump("CultureInfo");
dtf.FullDateTimePattern.Dump("FullDateTimePattern");
dtf.LongDatePattern.Dump("LongDatePattern");
dtf.LongTimePattern.Dump("LongTimePattern");
I select English (South Africa) as my format in the region dialog and my snippet reports the following.
E:\Junk>lprun CurrentCulture.linq
CultureInfo: en-ZA
FullDateTimePattern: dd MMMM yyyy hh:mm:ss tt
LongDatePattern: dd MMMM yyyy
LongTimePattern: hh:mm:ss tt
Then I change the long date format to hide leading zero on the day and the long and short time to be 24 hour time. The snippet now reports this.
E:\Junk>lprun CurrentCulture.linq
CultureInfo: en-ZA
FullDateTimePattern: d MMMM yyyy HH:mm:ss
LongDatePattern: d MMMM yyyy
LongTimePattern: HH:mm:ss
Although the culture names remain the same the properties I've changed are showing me the new values.
My question is whether there is a single property or method that will tell me whether the culture returned by CurrentCulture has been changed from its default (en-ZA in this case) or not. I thought that CultureInfo.UseUserOverride might be that property but it returns true in either case.
You can't ask if the culture has been changed by the user but you can request a culture that has not been changed by the user.
new CultureInfo(CultureInfo.CurrentCulture.Name, false);
or
CultureInfo::GetCultureInfo(CultureInfo.CurrentCulture.Name);
In either of these, the UseUserOverrides property will be false.
Only the default culture can have its data overridden by the user. An administrator can override the data in any culture by installing a custom replacement culture. You can detect that by checking the CultureTypes property for the presence of the CultureTypes.ReplacementCultures flag. There is no way to get the original data in that case.
Note that if you are actually trying to write code that changes its behavior based on this, you probably are writing code that will be broken by future releases. The data does change between releases as bugs are fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With