So, I have a few resource files for localization. They’re strings that can be formatted.
For example:
MyResource.resx
Title: "MyApp - Ver: {0}"
I then return it by doing like so:
public String Title
{
get { return String.Format(CultureInfo.CurrentUICulture, MyResources.Title, 1); }
}
I understand the difference between CurrentUICulture and CurrentCulture, but FxCop is telling me to use CurrentCulture instead?
To some extent FxCop is right: you should not use
CurrentUICulturein this case. As others already said,CurrentCultureis meant for Locale-aware formatting, whereasCurrentUICultureis meant for reading translatable strings from resources.What you did here, was formatting number, therefore FxCop complains that you used incorrect
CultureInfo. Unfortunately, what FxCop did not tell you is, you should in fact useCultureInfo.InvariantCulture. Why? Because version number is something that does not depend on Locale. You will always see something like 1.9 and not something like 1,9. ThusInvariantCultureis the way to go.Microsoft even provided specific class to store version information – oddly enough its name is
Version(AFAIR it is inSystemnamespace). This will always present you version numbers like I mentioned before, when you doToString(). Its constructor also expects Locale-invariant version string when you instantiate it.