feat(*): Add a helper method for listing country codes

This commit is contained in:
Josh Creek
2021-05-23 21:37:32 +01:00
parent ab2478ab67
commit e64390f257
2 changed files with 31 additions and 0 deletions
+1
View File
@@ -16,6 +16,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ConsoleTables" Version="2.4.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
+30
View File
@@ -31,6 +31,13 @@ namespace CityFinder
{ {
private static readonly HttpClient client = new HttpClient(); private static readonly HttpClient client = new HttpClient();
private static IConfigurationRoot config; private static IConfigurationRoot config;
private struct CountryCode
{
public String CountryName { get; set; }
public String TwoLetterCode { get; set; }
}
private static async Task Main(string[] args) private static async Task Main(string[] args)
{ {
InitialSetup(); InitialSetup();
@@ -49,6 +56,29 @@ namespace CityFinder
// Set default user-agent on the HttpClient to enable using the Google API from code // 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"); 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");
} }
/// <summary>
/// This method displays a table of valid country codes.
/// </summary>
private static void ListCountryCodes()
{
IEnumerable<RegionInfo> region = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(x => new RegionInfo(x.LCID));
List<CountryCode> countries = (from x in region select new CountryCode { CountryName = x.EnglishName, TwoLetterCode = x.TwoLetterISORegionName })
.Distinct()
.OrderBy(x => x.CountryName)
.ToList<CountryCode>();
ConsoleTable table = new ConsoleTable("Country", "Country Code");
foreach (CountryCode country in countries)
{
table.AddRow(country.CountryName, country.TwoLetterCode);
}
table.Write();
Console.WriteLine();
} }
} }
} }