cesarsouza / segn

Strongly typed enumerations for country names, ISO-3166-1 codes, and other GeoNames-based data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System.Enums.GeoNames (segn)

This super small project can be used to generate strongly-typed enumerations for country names and other information contained in the GeoNames database. You can use it to generate enum types to copy and paste into your projects. To generate a custom enumeration, just download the source and customize which properties from NGeoNames.CountryInfo you would like to see in your enumeration by changing the main program:

var sb = new StringBuilder();
sb.AppendLine("using System.ComponentModel.DataAnnotations;");
sb.AppendLine();
sb.AppendLine("public enum Countries");
sb.AppendLine("{");
foreach (CountryInfo country in countries)
{
    sb.AppendLine(format(
        name: country.Country,
        groupName: country.Continent,
        description: country.ISO_Numeric,
        shortName: country.ISO_Alpha2,
        memberName: country.ISO_Alpha3,
        value: country.GeoNameId
    ));
}
sb.AppendLine("}");

With just a few modifications you can also use it to generate state/region names and/or include additional information, such as currency, languages, or set the enum value directly to the respective ISO-3166-1 code for each country.

If you just want to see an enum you can copy-paste into your projects, just copy it from here.


See also:

About

Strongly typed enumerations for country names, ISO-3166-1 codes, and other GeoNames-based data

License:MIT License


Languages

Language:C# 100.0%