GetField & Turkish Locale

time to read 2 min | 367 words

I've just got an email about an interesting problem with NHibernate. After searching for a little while, I came up with the conclution that the problem is in the framework, and I can't see an easy solution for it.

First, let's start by explaining Turkish locale & its unique interpretation of the humble i letter. This MSDN article does it best, so I'll let them do the job:

For nearly all Latin alphabets, including U.S. English, the character i (\u0069) is the lowercase version of the character I (\u0049). This casing rule quickly becomes the default for someone programming in such a culture. However, in Turkish ("tr-TR"), there exists a capital "i with a dot,"  character (\u0130), which is the capital version of i. Similarly, in Turkish, there is a lowercase "i without a dot," or (\u0131), which capitalizes to I. This behavior occurs in the Azeri culture ("az") as well.

How does it has anything to do with NHibernate? Well, consider this code:

typeof(Blog).GetField("id")

This code will fail to return anything if the locale is set to Turkish. And the problem is worse because there doesn't seem to be a way to pass an InvariantCulture or Ordinal to the GetField method. The only solution that I can see now if to get all the fields on the method and iterate over them one by one, making a culture insensitive comparision.

Please tell me that I'm missing something, since this seems to indicate that any Reflection code will likely break if you're using the Turkish locale.

Oh, and that is the behavior for both .Net 1.0 & .Net 2.0