- I have local machine with locale:
en-US
- I have build machine with locale:
en-US-POSIX
- I have prod (AWS dotnet lambda) machine with locale:
en_US.UTF-8
I have this piece of code to get proper casing for a database field:
public string FixFieldCaseName(string fieldName)
{
var mappings = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
mappings.Add("test", "Test");
if (mappings.TryGetValue(fieldName, out var fixedFieldName) && fixedFieldName != fieldName)
{
_logger.Debug("stuff");
return fixedFieldName;
}
return fieldName;
}
This works locally and on the lambda, but not on the build machines. It returns me the original string.
Local and Lambda: input ("TeSt") -> output ("Test")
Build machine: input ("TeSt") -> output ("TeSt")
It doesn't work on Ubuntu due to the locale (en-US-POSIX): https://github.com/dotnet/corefx/issues/17052
Field names are used to perform queries in the database.
What is the proper way to fix this?
- I'm not sure whether to use OrdinalIgnoreCase or InvariantCultureIgnoreCase, even AFTER I reread best practices on MSFT Page.
OR
- Should I set the culture everywhere in my code?
System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Thanks for any help.