private void PerformAbbreviationMapping(Type unitType, int unitValue, IFormatProvider formatProvider, bool setAsDefault, params string[] abbreviations) { if (!unitType.IsEnum) throw new ArgumentException("Must be an enum type.", nameof(unitType)); if (abbreviations == null) throw new ArgumentNullException(nameof(abbreviations)); formatProvider = formatProvider ?? CultureInfo.CurrentUICulture; if (!_lookupsForCulture.TryGetValue(formatProvider, out var quantitiesForProvider)) quantitiesForProvider = _lookupsForCulture[formatProvider] = new UnitTypeToLookup(); if (!quantitiesForProvider.TryGetValue(unitType, out var unitToAbbreviations)) unitToAbbreviations = quantitiesForProvider[unitType] = new UnitValueAbbreviationLookup(); foreach (var abbr in abbreviations) { unitToAbbreviations.Add(unitValue, abbr, setAsDefault); } }
internal bool TryGetUnitValueAbbreviationLookup(Type unitType, IFormatProvider formatProvider, out UnitValueAbbreviationLookup unitToAbbreviations) { unitToAbbreviations = null; formatProvider = formatProvider ?? CultureInfo.CurrentUICulture; if (!_lookupsForCulture.TryGetValue(formatProvider, out var quantitiesForProvider)) return formatProvider != FallbackCulture ? TryGetUnitValueAbbreviationLookup(unitType, FallbackCulture, out unitToAbbreviations) : false; if (!quantitiesForProvider.TryGetValue(unitType, out unitToAbbreviations)) return formatProvider != FallbackCulture ? TryGetUnitValueAbbreviationLookup(unitType, FallbackCulture, out unitToAbbreviations) : false; return true; }