/// <summary> /// Actively initializes the information for all currencies. /// </summary> /// <remarks>Use this method if you plan to use a lot of currencies in your program. /// <para>When most of currencies are expected to be used, it is recommeneded to initialize the information for all of them, /// saving time each time the first instance is accessed.</para></remarks> public static void InitializeAllCurrencies() { CurrencyIsoCode[] isoCodes = Enumeration.GetValues <CurrencyIsoCode>(); using (var initializer = CurrencyInfo.CreateInitializer()) { for (int i = 0; i < isoCodes.Length; i++) { CurrencyIsoCode isoCode = isoCodes[i]; var copy = initializer; CurrencyCache.GetOrAdd(isoCode, () => init(isoCode, copy.Get)); } } }
public static bool TryGet(CurrencyIsoCode isoCode, out Currency currency) { bool tryGet = false; currency = null; if (Enumeration.CheckDefined(isoCode)) { tryGet = true; currency = CurrencyCache.GetOrAdd(isoCode, () => init(isoCode, _provider.Get)); } RaiseIfObsolete(currency); return(tryGet); }
public static IEnumerable <Currency> FindAll() { CurrencyIsoCode[] isoCodes = Enumeration.GetValues <CurrencyIsoCode>(); using (var initializer = CurrencyInfo.CreateInitializer()) { for (int i = 0; i < isoCodes.Length; i++) { CurrencyIsoCode isoCode = isoCodes[i]; var copy = initializer; Currency currency = CurrencyCache.GetOrAdd(isoCode, () => init(isoCode, copy.Get)); RaiseIfObsolete(isoCode); yield return(currency); } } }
public static Currency Get(string threeLetterIsoCode) { Currency currency = CurrencyCache.GetOrAdd(threeLetterIsoCode, () => { var isoCode = Code.ParseArgument(threeLetterIsoCode, nameof(threeLetterIsoCode)); var built = init(isoCode, _provider.Get); if (built == null) { throw new MisconfiguredCurrencyException(isoCode); } return(built); }); RaiseIfObsolete(currency); return(currency); }
public static bool TryGet(string threeLetterIsoSymbol, out Currency currency) { bool tryGet = false; currency = null; CurrencyIsoCode?isoCode; if (threeLetterIsoSymbol != null && Enumeration.TryParse(threeLetterIsoSymbol.ToUpperInvariant(), out isoCode)) { tryGet = true; currency = CurrencyCache.GetOrAdd(isoCode.GetValueOrDefault(), () => init(isoCode.GetValueOrDefault(), _provider.Get)); } RaiseIfObsolete(currency); return(tryGet); }
public static Currency Get(CurrencyIsoCode isoCode) { Enumeration.AssertDefined(isoCode); Currency currency = CurrencyCache.GetOrAdd(isoCode, () => { var built = init(isoCode, _provider.Get); if (built == null) { throw new MisconfiguredCurrencyException(isoCode); } return(built); }); RaiseIfObsolete(isoCode); return(currency); }