@@ -354,66 +354,41 @@ public override int GetHashCode()
354
354
#endregion
355
355
356
356
#region Conversion
357
-
357
+
358
358
/// <summary>
359
- /// Try to dynamically convert from Area to <paramref name="toUnit "/>.
359
+ /// Convert to the unit representation in <paramref name="asUnit "/>.
360
360
/// </summary>
361
361
/// <param name="toUnit">Compatible unit to convert to.</param>
362
- /// <param name="newValue" >Value in new unit if successful, zero otherwise.</param>
363
- /// <returns>True if the two units were compatible and the conversion was successful.</returns>
364
- public bool TryConvert ( AreaUnit toUnit , out double newValue )
362
+ /// <returns >Value in new unit if successful, exception otherwise.</returns>
363
+ /// <exception cref="NotImplementedException">If conversion was not successful.</exception>
364
+ public double As ( AreaUnit unit )
365
365
{
366
- switch ( toUnit )
366
+ switch ( unit )
367
367
{
368
368
case AreaUnit . SquareCentimeter :
369
- newValue = SquareCentimeters ;
370
- return true ;
369
+ return SquareCentimeters ;
371
370
case AreaUnit . SquareDecimeter :
372
- newValue = SquareDecimeters ;
373
- return true ;
371
+ return SquareDecimeters ;
374
372
case AreaUnit . SquareFoot :
375
- newValue = SquareFeet ;
376
- return true ;
373
+ return SquareFeet ;
377
374
case AreaUnit . SquareInch :
378
- newValue = SquareInches ;
379
- return true ;
375
+ return SquareInches ;
380
376
case AreaUnit . SquareKilometer :
381
- newValue = SquareKilometers ;
382
- return true ;
377
+ return SquareKilometers ;
383
378
case AreaUnit . SquareMeter :
384
- newValue = SquareMeters ;
385
- return true ;
379
+ return SquareMeters ;
386
380
case AreaUnit . SquareMile :
387
- newValue = SquareMiles ;
388
- return true ;
381
+ return SquareMiles ;
389
382
case AreaUnit . SquareMillimeter :
390
- newValue = SquareMillimeters ;
391
- return true ;
383
+ return SquareMillimeters ;
392
384
case AreaUnit . SquareYard :
393
- newValue = SquareYards ;
394
- return true ;
385
+ return SquareYards ;
395
386
396
387
default :
397
- newValue = 0 ;
398
- return false ;
388
+ throw new NotImplementedException ( "unit: " + unit ) ;
399
389
}
400
390
}
401
391
402
- /// <summary>
403
- /// Dynamically convert from Area to <paramref name="toUnit"/>.
404
- /// </summary>
405
- /// <param name="toUnit">Compatible unit to convert to.</param>
406
- /// <returns>Value in new unit if successful, exception otherwise.</returns>
407
- /// <exception cref="NotImplementedException">If conversion was not successful.</exception>
408
- public double Convert ( AreaUnit toUnit )
409
- {
410
- double newValue ;
411
- if ( ! TryConvert ( toUnit , out newValue ) )
412
- throw new NotImplementedException ( "toUnit: " + toUnit ) ;
413
-
414
- return newValue ;
415
- }
416
-
417
392
#endregion
418
393
419
394
/// <summary>
@@ -438,7 +413,7 @@ public string ToString(AreaUnit unit, CultureInfo culture = null)
438
413
public string ToString ( AreaUnit unit , CultureInfo culture , string format , params object [ ] args )
439
414
{
440
415
string abbreviation = UnitSystem . GetCached ( culture ) . GetDefaultAbbreviation ( unit ) ;
441
- var finalArgs = new object [ ] { Convert ( unit ) , abbreviation }
416
+ var finalArgs = new object [ ] { As ( unit ) , abbreviation }
442
417
. Concat ( args )
443
418
. ToArray ( ) ;
444
419
0 commit comments