From c80c48d79bf0cad8c4c9556a95a949fdb8105d71 Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Mon, 16 Sep 2024 11:54:52 +0200 Subject: [PATCH 1/2] alpha code conversions + add extension to convert alpha code 2 to alpha code 3 and vice versa --- src/Nager.Country/AlphaCodeConversionExtensions.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/Nager.Country/AlphaCodeConversionExtensions.cs diff --git a/src/Nager.Country/AlphaCodeConversionExtensions.cs b/src/Nager.Country/AlphaCodeConversionExtensions.cs new file mode 100644 index 0000000..e3ce5dd --- /dev/null +++ b/src/Nager.Country/AlphaCodeConversionExtensions.cs @@ -0,0 +1,14 @@ +namespace Nager.Country; + +public static class AlphaCodeConversionExtensions +{ + public static Alpha3Code ToAlpha3Code( this Alpha2Code code ) + { + return (Alpha3Code)code; + } + + public static Alpha2Code ToAlpha2Code( this Alpha3Code code ) + { + return (Alpha2Code)code; + } +} \ No newline at end of file From 9a5b082727a5c5dfcc339156b3fc9f6b9255d02b Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Mon, 16 Sep 2024 11:55:27 +0200 Subject: [PATCH 2/2] country info by region + add extension to get countries by region or sub region --- src/Nager.Country/CountryProviderExtensions.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/Nager.Country/CountryProviderExtensions.cs diff --git a/src/Nager.Country/CountryProviderExtensions.cs b/src/Nager.Country/CountryProviderExtensions.cs new file mode 100644 index 0000000..e0bb3a9 --- /dev/null +++ b/src/Nager.Country/CountryProviderExtensions.cs @@ -0,0 +1,15 @@ +namespace Nager.Country; + +public static class CountryProviderExtensions +{ + public static IEnumerable GetCountriesByRegion( this ICountryProvider provider, Region region ) + { + return provider.GetCountries().Where( x => x.Region == region ); + } + + public static IEnumerable GetCountriesBySubRegion( this ICountryProvider provider, + SubRegion subRegion ) + { + return provider.GetCountries().Where( x => x.SubRegion == subRegion ); + } +} \ No newline at end of file