@@ -116,7 +116,7 @@ public void MapUnitToAbbreviation<TUnitType>(TUnitType unit, params IEnumerable<
116
116
/// <param name="abbreviations">Unit abbreviations to add.</param>
117
117
public void MapUnitToAbbreviation ( Type unitType , int unitValue , IFormatProvider ? formatProvider , params IEnumerable < string > abbreviations )
118
118
{
119
- MapUnitToAbbreviation ( new UnitKey ( unitType , unitValue ) , formatProvider , abbreviations ) ;
119
+ MapUnitToAbbreviation ( UnitKey . Create ( unitType , unitValue ) , formatProvider , abbreviations ) ;
120
120
}
121
121
122
122
/// <inheritdoc cref="MapUnitToAbbreviation{TUnitType}(TUnitType,IEnumerable{string})"/>>
@@ -159,6 +159,10 @@ public void MapUnitToAbbreviation(UnitKey unitKey, IFormatProvider? formatProvid
159
159
/// <param name="unit">The unit enum value.</param>
160
160
/// <param name="abbreviation">Unit abbreviations to add as default.</param>
161
161
/// <typeparam name="TUnitType">The type of unit enum.</typeparam>
162
+ /// <exception cref="UnitNotFoundException">
163
+ /// Thrown when no unit information is found for the specified
164
+ /// <paramref name="unit" />.
165
+ /// </exception>
162
166
public void MapUnitToDefaultAbbreviation < TUnitType > ( TUnitType unit , string abbreviation )
163
167
where TUnitType : struct , Enum
164
168
{
@@ -189,9 +193,15 @@ public void MapUnitToDefaultAbbreviation<TUnitType>(TUnitType unit, IFormatProvi
189
193
/// <param name="unitValue">The unit enum value.</param>
190
194
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="CultureInfo.CurrentCulture" /> if null.</param>
191
195
/// <param name="abbreviation">Unit abbreviation to add as default.</param>
196
+ /// <exception cref="ArgumentNullException">
197
+ /// Thrown when the provided type is null.
198
+ /// </exception>
199
+ /// <exception cref="ArgumentException">
200
+ /// Thrown when the provided type is not an enumeration type.
201
+ /// </exception>
192
202
public void MapUnitToDefaultAbbreviation ( Type unitType , int unitValue , IFormatProvider ? formatProvider , string abbreviation )
193
203
{
194
- MapUnitToDefaultAbbreviation ( new UnitKey ( unitType , unitValue ) , formatProvider , abbreviation ) ;
204
+ MapUnitToDefaultAbbreviation ( UnitKey . Create ( unitType , unitValue ) , formatProvider , abbreviation ) ;
195
205
}
196
206
197
207
/// <inheritdoc cref="MapUnitToDefaultAbbreviation{TUnitType}(TUnitType,string)"/>>
@@ -240,6 +250,12 @@ public string GetDefaultAbbreviation<TUnitType>(TUnitType unit, IFormatProvider?
240
250
/// <param name="unitType">The unit enum type.</param>
241
251
/// <param name="unitValue">The unit enum value.</param>
242
252
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="CultureInfo.CurrentCulture" /> if null.</param>
253
+ /// <exception cref="ArgumentNullException">
254
+ /// Thrown when the provided type is null.
255
+ /// </exception>
256
+ /// <exception cref="ArgumentException">
257
+ /// Thrown when the provided type is not an enumeration type.
258
+ /// </exception>
243
259
/// <exception cref="UnitNotFoundException">
244
260
/// Thrown when no unit information is found for the specified
245
261
/// <paramref name="unitType" /> and <paramref name="unitValue" />.
@@ -249,7 +265,7 @@ public string GetDefaultAbbreviation<TUnitType>(TUnitType unit, IFormatProvider?
249
265
/// </exception>
250
266
public string GetDefaultAbbreviation ( Type unitType , int unitValue , IFormatProvider ? formatProvider = null )
251
267
{
252
- return GetDefaultAbbreviation ( new UnitKey ( unitType , unitValue ) , formatProvider ) ;
268
+ return GetDefaultAbbreviation ( UnitKey . Create ( unitType , unitValue ) , formatProvider ) ;
253
269
}
254
270
255
271
/// <inheritdoc cref="GetDefaultAbbreviation{TUnitType}" />
@@ -297,13 +313,19 @@ public IReadOnlyList<string> GetUnitAbbreviations<TUnitType>(TUnitType unit, IFo
297
313
/// <param name="unitValue">Enum value for unit.</param>
298
314
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="CultureInfo.CurrentCulture" /> if null.</param>
299
315
/// <returns>Unit abbreviations associated with unit.</returns>
316
+ /// <exception cref="ArgumentNullException">
317
+ /// Thrown when the provided type is null.
318
+ /// </exception>
319
+ /// <exception cref="ArgumentException">
320
+ /// Thrown when the provided type is not an enumeration type.
321
+ /// </exception>
300
322
/// <exception cref="UnitNotFoundException">
301
323
/// Thrown when no unit information is found for the specified
302
324
/// <paramref name="unitType" /> and <paramref name="unitValue" />.
303
325
/// </exception>
304
326
public IReadOnlyList < string > GetUnitAbbreviations ( Type unitType , int unitValue , IFormatProvider ? formatProvider = null )
305
327
{
306
- return GetUnitAbbreviations ( new UnitKey ( unitType , unitValue ) , formatProvider ) ;
328
+ return GetUnitAbbreviations ( UnitKey . Create ( unitType , unitValue ) , formatProvider ) ;
307
329
}
308
330
309
331
/// <summary>
@@ -336,19 +358,27 @@ public IReadOnlyList<string> GetUnitAbbreviations(UnitKey unitKey, IFormatProvid
336
358
/// <returns>
337
359
/// A read-only list of unit abbreviations associated with the specified unit type.
338
360
/// </returns>
361
+ /// <exception cref="ArgumentNullException">
362
+ /// Thrown when the provided type is null.
363
+ /// </exception>
339
364
/// <exception cref="ArgumentException">
340
- /// Thrown when the provided <paramref name="unitEnumType" /> is not an enum type.
365
+ /// Thrown when the provided type is not an enumeration type.
341
366
/// </exception>
342
367
/// <exception cref="UnitNotFoundException">
343
368
/// Thrown when no quantity is found for the specified unit type.
344
369
/// </exception>
345
370
public IReadOnlyList < string > GetAllUnitAbbreviationsForQuantity ( Type unitEnumType , IFormatProvider ? formatProvider = null )
346
371
{
372
+ if ( unitEnumType == null )
373
+ {
374
+ throw new ArgumentNullException ( nameof ( unitEnumType ) ) ;
375
+ }
376
+
347
377
if ( ! Quantities . TryGetQuantityByUnitType ( unitEnumType , out QuantityInfo ? quantityInfo ) )
348
378
{
349
379
if ( ! unitEnumType . IsEnum )
350
380
{
351
- throw new ArgumentException ( $ "Type { unitEnumType . FullName } is not a supported unit type." ) ;
381
+ throw new ArgumentException ( $ "Unit type must be an enumeration, but was { unitEnumType . FullName } ." , nameof ( unitEnumType ) ) ;
352
382
}
353
383
354
384
throw new UnitNotFoundException ( $ "No quantity was found with the specified unit type: '{ unitEnumType } '.") { Data = { [ "unitType" ] = unitEnumType . Name } } ;
0 commit comments