public static IEnumerable <ExtendedCultureInfo> GetFallBack( [NotNull] this ICultureInfoProvider provider, [NotNull] CultureInfo culture) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } if (culture == null) { throw new ArgumentNullException(nameof(culture)); } ExtendedCultureInfo extendedCultureInfo = provider.Get(culture); if (extendedCultureInfo == null) { throw new ArgumentException( string.Format(Resources.CultureHelper_GetFallBack_UnknownCulture, culture), nameof(culture)); } HashSet <ExtendedCultureInfo> yielded = new HashSet <ExtendedCultureInfo>(); // First return the culture passed in yield return(extendedCultureInfo); yielded.Add(extendedCultureInfo); // Next return any descendants in a breadth first order Queue <ExtendedCultureInfo> queue = new Queue <ExtendedCultureInfo>(provider.GetChildren(extendedCultureInfo)); while (queue.TryDequeue(out ExtendedCultureInfo childCulture)) { yield return(childCulture); foreach (ExtendedCultureInfo child in provider.GetChildren(childCulture)) { queue.Enqueue(child); } } // Lastly return the ancestors and each ones children, excluding invariant extendedCultureInfo = extendedCultureInfo.Parent; while (!extendedCultureInfo.IsInvariant) { yield return(extendedCultureInfo); yielded.Add(extendedCultureInfo); foreach (ExtendedCultureInfo child in provider.GetChildren(extendedCultureInfo)) { if (!yielded.Contains(child)) { yield return(child); } } extendedCultureInfo = extendedCultureInfo.Parent; } if (!yielded.Contains(extendedCultureInfo)) { yield return(extendedCultureInfo); } }
/// <summary> /// Gets the specified culture information. /// </summary> /// <param name="cultureInfo">The culture information.</param> /// <returns></returns> public CurrencyInfo Get(ExtendedCultureInfo cultureInfo) { CurrencyInfo currencyInfo; return cultureInfo.RegionInfo != null && _currencyInfos.TryGetValue(cultureInfo.RegionInfo.ISOCurrencySymbol, out currencyInfo) ? currencyInfo : null; }
/// <summary> /// Gets the <see cref="CurrencyInfo" /> from the specified extended culture information. /// </summary> /// <param name="cultureInfo">The culture information.</param> /// <returns> /// The associated <see cref="CurrencyInfo" /> if found; otherwise <see langword="null" />. /// </returns> public CurrencyInfo Get(ExtendedCultureInfo cultureInfo) { return(null); }
/// <summary> /// Gets the <see cref="CurrencyInfo" /> from the specified extended culture information. /// </summary> /// <param name="cultureInfo">The culture information.</param> /// <returns> /// The associated <see cref="CurrencyInfo" /> if found; otherwise <see langword="null" />. /// </returns> public CurrencyInfo Get(ExtendedCultureInfo cultureInfo) { return null; }