Skip to content

Commit e4c8350

Browse files
committed
Optimize performance of GetCountryByNameConsiderTranslation
#29
1 parent 1afce7d commit e4c8350

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Nager.Country.Translation/CountryProviderExtension.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
namespace Nager.Country.Translation
55
{
6+
/// <summary>
7+
/// CountryProvider Extension
8+
/// </summary>
69
public static class CountryProviderExtension
710
{
11+
private static readonly Lazy<TranslationProvider> TranslationProvider = new Lazy<TranslationProvider>();
12+
813
///<inheritdoc/>
914
public static ICountryInfo GetCountryByNameConsiderTranslation(
1015
this ICountryProvider countryProvider,
@@ -24,9 +29,8 @@ public static ICountryInfo GetCountryByNameConsiderTranslation(
2429
return country;
2530
}
2631

27-
var translationProvider = new TranslationProvider();
28-
var countryTranslation = translationProvider.GetCountryTranslation(country.Alpha2Code);
29-
if (countryTranslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase)))
32+
var countryTanslation = TranslationProvider.Value.GetCountryTranslation(country.Alpha2Code);
33+
if (countryTanslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase)))
3034
{
3135
return country;
3236
}

0 commit comments

Comments
 (0)