Country tag helper–part 1


What I want to do is to create a Country Tag Helper for core.

Something like

<select asp-country=”true”

and then list all countries in this select. More, it should be localized ( Germany vs Allemagne). That means 1 or more resource files 


First I need initial data: The WorldBank API gives us the names and I have made a project that inspects that API.

To retrieve data in resource format , it is simple:

 var r = new CountriesRepository();
            var arr = r.GetCountries().Result.
                Select(it =>
                $"<data name = \"{it.iso2Code}\" xml:space=\"preserve\" >" +

                $"<value>{}</value>" +
            var s = string.Join(Environment.NewLine, arr);
            File.WriteAllText(@"D:\c.txt", s);


Then we could copy paste into resources:

 <data name = "AW" xml:space="preserve" ><value>Aruba</value></data>
  <data name = "AF" xml:space="preserve" ><value>Afghanistan</value></data>
  <data name = "AO" xml:space="preserve" ><value>Angola</value></data>


Now I want to make a list of those names – so I need this code to translate between C# generated code from resource

public static string AD {
            get {
                return ResourceManager.GetString("AD", resourceCulture);
public static string AE {
            get {
                return ResourceManager.GetString("AE", resourceCulture);


and a list of names to be put into select.

Reflection to the rescue:

  var t =typeof( ResCTH);
            properties= t.GetProperties(
                BindingFlags.Public |
                BindingFlags.Static |
            CountryISO = properties
                .Select(it => it.Name)


The code is on github and I will improve next time.