From e64390f2577fc0be735bdd4bb671523b85eebd74 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Sun, 23 May 2021 21:37:32 +0100 Subject: [PATCH] feat(*): Add a helper method for listing country codes --- CityFinder/CityFinder.csproj | 1 + CityFinder/Program.cs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CityFinder/CityFinder.csproj b/CityFinder/CityFinder.csproj index 9689360..29f5640 100644 --- a/CityFinder/CityFinder.csproj +++ b/CityFinder/CityFinder.csproj @@ -16,6 +16,7 @@ + diff --git a/CityFinder/Program.cs b/CityFinder/Program.cs index 7530f5f..e639879 100644 --- a/CityFinder/Program.cs +++ b/CityFinder/Program.cs @@ -31,6 +31,13 @@ namespace CityFinder { private static readonly HttpClient client = new HttpClient(); private static IConfigurationRoot config; + + private struct CountryCode + { + public String CountryName { get; set; } + public String TwoLetterCode { get; set; } + } + private static async Task Main(string[] args) { InitialSetup(); @@ -49,6 +56,29 @@ namespace CityFinder // Set default user-agent on the HttpClient to enable using the Google API from code client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"); } + + /// + /// This method displays a table of valid country codes. + /// + private static void ListCountryCodes() + { + IEnumerable region = CultureInfo.GetCultures(CultureTypes.SpecificCultures) + .Select(x => new RegionInfo(x.LCID)); + + List countries = (from x in region select new CountryCode { CountryName = x.EnglishName, TwoLetterCode = x.TwoLetterISORegionName }) + .Distinct() + .OrderBy(x => x.CountryName) + .ToList(); + + ConsoleTable table = new ConsoleTable("Country", "Country Code"); + + foreach (CountryCode country in countries) + { + table.AddRow(country.CountryName, country.TwoLetterCode); + } + + table.Write(); + Console.WriteLine(); } } }