0

I'm sorry if this is a stupid question but if I want to return column depending on culture, what would the best way be?

I've thought of having if elses in the linq select statement

or making an extension: Say I use code first with linq and have a class Country with an empty Name and Name_fr, Name_no, Name_** etc.

    public static IEnumerable<Country> C(this IEnumerable<Country> Countries)
    {
        if (Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName == "en")
        {
            return Countries.Select(x => new Country { x.Name = x.Name_en });
        }
    }

Is there a standard way of more than string data from resx based on culture? I'm sorry if this is a duplicate, but I couldn't find the answer.

Cheers, Hawk

Hawk
  • 1,513
  • 1
  • 14
  • 17

1 Answers1

1

Try like this

    public static IEnumerable<Country> C(this IEnumerable<Country> Countries)
    {
        var propName = string.Format("Name_{0}", Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
        var localizedNameProp = typeof(Country).GetProperty(propName);

        return Countries.Select(x => new Country { Name = localizedNameProp.GetValue(x, null).ToString() });
    }
Khurshid
  • 954
  • 7
  • 19
  • Thanks. Was hoping there was a different approach, but I'll stick with extension methods then:) – Hawk May 01 '13 at 08:32