|
8 | 8 | using System.Linq;
|
9 | 9 | using System.Resources;
|
10 | 10 | using UnitsNet.InternalHelpers;
|
| 11 | +using System.Diagnostics.CodeAnalysis; |
11 | 12 | using UnitsNet.Units;
|
12 | 13 | using AbbreviationMapKey = System.ValueTuple<UnitsNet.UnitKey, string>;
|
13 | 14 |
|
@@ -275,16 +276,19 @@ private bool TryGetUnitAbbreviations(UnitKey unitKey, IFormatProvider? formatPro
|
275 | 276 | /// <param name="unitEnumType">Enum type for unit.</param>
|
276 | 277 | /// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="CultureInfo.CurrentCulture" /> if null.</param>
|
277 | 278 | /// <returns>Unit abbreviations associated with unit.</returns>
|
278 |
| - [RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetAllUnitAbbreviationsForQuantity<TEnum> overload.")] |
| 279 | + /// <exception cref="QuantityNotFoundException"> |
| 280 | + /// Thrown when no quantity information is found for the specified unit enum type. |
| 281 | + /// </exception> |
279 | 282 | public IReadOnlyList<string> GetAllUnitAbbreviationsForQuantity(Type unitEnumType, IFormatProvider? formatProvider = null)
|
280 | 283 | {
|
281 | 284 | var allAbbreviations = new List<string>();
|
282 | 285 | if (!QuantityInfoLookup.TryGetQuantityByUnitType(unitEnumType, out QuantityInfo? quantityInfo))
|
283 | 286 | {
|
284 | 287 | // TODO I think we should either return empty or throw QuantityNotFoundException here
|
285 |
| - var enumValues = Enum.GetValues(unitEnumType).Cast<Enum>(); |
286 |
| - var all = GetStringUnitPairs(enumValues, formatProvider); |
287 |
| - return all.Select(pair => pair.Item2).ToList(); |
| 288 | + // var enumValues = Enum.GetValues(unitEnumType).Cast<Enum>(); |
| 289 | + // var all = GetStringUnitPairs(enumValues, formatProvider); |
| 290 | + // return all.Select(pair => pair.Item2).ToList(); |
| 291 | + throw new QuantityNotFoundException("No quantity information was found for the type."); |
288 | 292 | }
|
289 | 293 |
|
290 | 294 | foreach(UnitInfo unitInfo in quantityInfo.UnitInfos)
|
|
0 commit comments