@@ -43,6 +43,7 @@ public static double Convert(double value, Unit fromUnit, Unit toUnit)
43
43
44
44
double newValue ;
45
45
if ( TryConvertLength ( value , fromUnit , toUnit , out newValue ) ) return newValue ;
46
+ if ( TryConvertArea ( value , fromUnit , toUnit , out newValue ) ) return newValue ;
46
47
if ( TryConvertVolume ( value , fromUnit , toUnit , out newValue ) ) return newValue ;
47
48
if ( TryConvertMass ( value , fromUnit , toUnit , out newValue ) ) return newValue ;
48
49
if ( TryConvertPressure ( value , fromUnit , toUnit , out newValue ) ) return newValue ;
@@ -213,6 +214,27 @@ private static bool TryConvertLength(double value, Unit fromUnit, Unit toUnit, o
213
214
}
214
215
}
215
216
217
+ private static bool TryConvertArea ( double value , Unit fromUnit , Unit toUnit , out double newValue )
218
+ {
219
+ switch ( fromUnit )
220
+ {
221
+ case Unit . SquareKilometer :
222
+ return TryConvert ( Area . FromSquareKilometers ( value ) , toUnit , out newValue ) ;
223
+ case Unit . SquareMeter :
224
+ return TryConvert ( Area . FromSquareMeters ( value ) , toUnit , out newValue ) ;
225
+ case Unit . SquareDecimeter :
226
+ return TryConvert ( Area . FromSquareDecimeters ( value ) , toUnit , out newValue ) ;
227
+ case Unit . SquareCentimeter :
228
+ return TryConvert ( Area . FromSquareCentimeters ( value ) , toUnit , out newValue ) ;
229
+ case Unit . SquareMillimeter :
230
+ return TryConvert ( Area . FromSquareMillimeters ( value ) , toUnit , out newValue ) ;
231
+
232
+ default :
233
+ newValue = 0 ;
234
+ return false ;
235
+ }
236
+ }
237
+
216
238
private static bool TryConvertVolume ( double value , Unit fromUnit , Unit toUnit , out double newValue )
217
239
{
218
240
switch ( fromUnit )
@@ -326,6 +348,32 @@ private static bool TryConvert(Length l, Unit toUnit, out double newValue)
326
348
}
327
349
}
328
350
351
+ private static bool TryConvert ( Area volume , Unit toUnit , out double newValue )
352
+ {
353
+ switch ( toUnit )
354
+ {
355
+ case Unit . SquareKilometer :
356
+ newValue = volume . SquareKilometers ;
357
+ return true ;
358
+ case Unit . SquareMeter :
359
+ newValue = volume . SquareMeters ;
360
+ return true ;
361
+ case Unit . SquareDecimeter :
362
+ newValue = volume . SquareDecimeters ;
363
+ return true ;
364
+ case Unit . SquareCentimeter :
365
+ newValue = volume . SquareCentimeters ;
366
+ return true ;
367
+ case Unit . SquareMillimeter :
368
+ newValue = volume . SquareMillimeters ;
369
+ return true ;
370
+
371
+ default :
372
+ newValue = 0 ;
373
+ return false ;
374
+ }
375
+ }
376
+
329
377
private static bool TryConvert ( Volume volume , Unit toUnit , out double newValue )
330
378
{
331
379
switch ( toUnit )
0 commit comments