Skip to content

Commit 6c83e6f

Browse files
tmilnthorpangularsen
authored andcommitted
Changing Compare methods to compare current value to other in "this" … (#454)
* Changing Compare methods to compare current value to other in "this" units. This avoids scaling issues (and converting two quantities when we only need to potentially convert one) when both "this" and "other" are not defined in base units. "This" is the reference value. * Use nameof(param) for parameter exceptions
1 parent 3af27fd commit 6c83e6f

File tree

91 files changed

+637
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+637
-546
lines changed

UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,10 @@ public static string GetAbbreviation(
736736

737737
public int CompareTo(object obj)
738738
{
739-
if (obj == null) throw new ArgumentNullException("obj");
740-
if (!(obj is Acceleration)) throw new ArgumentException("Expected type Acceleration.", "obj");
741-
return CompareTo((Acceleration) obj);
739+
if(obj is null) throw new ArgumentNullException(nameof(obj));
740+
if(!(obj is Acceleration)) throw new ArgumentException("Expected type Acceleration.", nameof(obj));
741+
742+
return CompareTo((Acceleration)obj);
742743
}
743744

744745
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -749,7 +750,7 @@ public int CompareTo(object obj)
749750
#endif
750751
int CompareTo(Acceleration other)
751752
{
752-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
753+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
753754
}
754755

755756
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1006,7 +1007,7 @@ public static Acceleration Parse(
10061007
[CanBeNull] IFormatProvider provider)
10071008
#endif
10081009
{
1009-
if (str == null) throw new ArgumentNullException("str");
1010+
if (str == null) throw new ArgumentNullException(nameof(str));
10101011

10111012
#if WINDOWS_UWP
10121013
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1134,7 +1135,7 @@ public static AccelerationUnit ParseUnit(string str, [CanBeNull] string cultureN
11341135
#endif
11351136
static AccelerationUnit ParseUnit(string str, IFormatProvider provider = null)
11361137
{
1137-
if (str == null) throw new ArgumentNullException("str");
1138+
if (str == null) throw new ArgumentNullException(nameof(str));
11381139

11391140
var unitSystem = UnitSystem.GetCached(provider);
11401141
var unit = unitSystem.Parse<AccelerationUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,10 @@ public static string GetAbbreviation(
769769

770770
public int CompareTo(object obj)
771771
{
772-
if (obj == null) throw new ArgumentNullException("obj");
773-
if (!(obj is AmountOfSubstance)) throw new ArgumentException("Expected type AmountOfSubstance.", "obj");
774-
return CompareTo((AmountOfSubstance) obj);
772+
if(obj is null) throw new ArgumentNullException(nameof(obj));
773+
if(!(obj is AmountOfSubstance)) throw new ArgumentException("Expected type AmountOfSubstance.", nameof(obj));
774+
775+
return CompareTo((AmountOfSubstance)obj);
775776
}
776777

777778
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -782,7 +783,7 @@ public int CompareTo(object obj)
782783
#endif
783784
int CompareTo(AmountOfSubstance other)
784785
{
785-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
786+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
786787
}
787788

788789
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1041,7 +1042,7 @@ public static AmountOfSubstance Parse(
10411042
[CanBeNull] IFormatProvider provider)
10421043
#endif
10431044
{
1044-
if (str == null) throw new ArgumentNullException("str");
1045+
if (str == null) throw new ArgumentNullException(nameof(str));
10451046

10461047
#if WINDOWS_UWP
10471048
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1169,7 +1170,7 @@ public static AmountOfSubstanceUnit ParseUnit(string str, [CanBeNull] string cul
11691170
#endif
11701171
static AmountOfSubstanceUnit ParseUnit(string str, IFormatProvider provider = null)
11711172
{
1172-
if (str == null) throw new ArgumentNullException("str");
1173+
if (str == null) throw new ArgumentNullException(nameof(str));
11731174

11741175
var unitSystem = UnitSystem.GetCached(provider);
11751176
var unit = unitSystem.Parse<AmountOfSubstanceUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,10 @@ public static string GetAbbreviation(
437437

438438
public int CompareTo(object obj)
439439
{
440-
if (obj == null) throw new ArgumentNullException("obj");
441-
if (!(obj is AmplitudeRatio)) throw new ArgumentException("Expected type AmplitudeRatio.", "obj");
442-
return CompareTo((AmplitudeRatio) obj);
440+
if(obj is null) throw new ArgumentNullException(nameof(obj));
441+
if(!(obj is AmplitudeRatio)) throw new ArgumentException("Expected type AmplitudeRatio.", nameof(obj));
442+
443+
return CompareTo((AmplitudeRatio)obj);
443444
}
444445

445446
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -450,7 +451,7 @@ public int CompareTo(object obj)
450451
#endif
451452
int CompareTo(AmplitudeRatio other)
452453
{
453-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
454+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
454455
}
455456

456457
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -689,7 +690,7 @@ public static AmplitudeRatio Parse(
689690
[CanBeNull] IFormatProvider provider)
690691
#endif
691692
{
692-
if (str == null) throw new ArgumentNullException("str");
693+
if (str == null) throw new ArgumentNullException(nameof(str));
693694

694695
#if WINDOWS_UWP
695696
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -817,7 +818,7 @@ public static AmplitudeRatioUnit ParseUnit(string str, [CanBeNull] string cultur
817818
#endif
818819
static AmplitudeRatioUnit ParseUnit(string str, IFormatProvider provider = null)
819820
{
820-
if (str == null) throw new ArgumentNullException("str");
821+
if (str == null) throw new ArgumentNullException(nameof(str));
821822

822823
var unitSystem = UnitSystem.GetCached(provider);
823824
var unit = unitSystem.Parse<AmplitudeRatioUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,10 @@ public static string GetAbbreviation(
759759

760760
public int CompareTo(object obj)
761761
{
762-
if (obj == null) throw new ArgumentNullException("obj");
763-
if (!(obj is Angle)) throw new ArgumentException("Expected type Angle.", "obj");
764-
return CompareTo((Angle) obj);
762+
if(obj is null) throw new ArgumentNullException(nameof(obj));
763+
if(!(obj is Angle)) throw new ArgumentException("Expected type Angle.", nameof(obj));
764+
765+
return CompareTo((Angle)obj);
765766
}
766767

767768
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -772,7 +773,7 @@ public int CompareTo(object obj)
772773
#endif
773774
int CompareTo(Angle other)
774775
{
775-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
776+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
776777
}
777778

778779
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1031,7 +1032,7 @@ public static Angle Parse(
10311032
[CanBeNull] IFormatProvider provider)
10321033
#endif
10331034
{
1034-
if (str == null) throw new ArgumentNullException("str");
1035+
if (str == null) throw new ArgumentNullException(nameof(str));
10351036

10361037
#if WINDOWS_UWP
10371038
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1159,7 +1160,7 @@ public static AngleUnit ParseUnit(string str, [CanBeNull] string cultureName)
11591160
#endif
11601161
static AngleUnit ParseUnit(string str, IFormatProvider provider = null)
11611162
{
1162-
if (str == null) throw new ArgumentNullException("str");
1163+
if (str == null) throw new ArgumentNullException(nameof(str));
11631164

11641165
var unitSystem = UnitSystem.GetCached(provider);
11651166
var unit = unitSystem.Parse<AngleUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,10 @@ public static string GetAbbreviation(
406406

407407
public int CompareTo(object obj)
408408
{
409-
if (obj == null) throw new ArgumentNullException("obj");
410-
if (!(obj is ApparentEnergy)) throw new ArgumentException("Expected type ApparentEnergy.", "obj");
411-
return CompareTo((ApparentEnergy) obj);
409+
if(obj is null) throw new ArgumentNullException(nameof(obj));
410+
if(!(obj is ApparentEnergy)) throw new ArgumentException("Expected type ApparentEnergy.", nameof(obj));
411+
412+
return CompareTo((ApparentEnergy)obj);
412413
}
413414

414415
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -419,7 +420,7 @@ public int CompareTo(object obj)
419420
#endif
420421
int CompareTo(ApparentEnergy other)
421422
{
422-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
423+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
423424
}
424425

425426
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -656,7 +657,7 @@ public static ApparentEnergy Parse(
656657
[CanBeNull] IFormatProvider provider)
657658
#endif
658659
{
659-
if (str == null) throw new ArgumentNullException("str");
660+
if (str == null) throw new ArgumentNullException(nameof(str));
660661

661662
#if WINDOWS_UWP
662663
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -784,7 +785,7 @@ public static ApparentEnergyUnit ParseUnit(string str, [CanBeNull] string cultur
784785
#endif
785786
static ApparentEnergyUnit ParseUnit(string str, IFormatProvider provider = null)
786787
{
787-
if (str == null) throw new ArgumentNullException("str");
788+
if (str == null) throw new ArgumentNullException(nameof(str));
788789

789790
var unitSystem = UnitSystem.GetCached(provider);
790791
var unit = unitSystem.Parse<ApparentEnergyUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,10 @@ public static string GetAbbreviation(
439439

440440
public int CompareTo(object obj)
441441
{
442-
if (obj == null) throw new ArgumentNullException("obj");
443-
if (!(obj is ApparentPower)) throw new ArgumentException("Expected type ApparentPower.", "obj");
444-
return CompareTo((ApparentPower) obj);
442+
if(obj is null) throw new ArgumentNullException(nameof(obj));
443+
if(!(obj is ApparentPower)) throw new ArgumentException("Expected type ApparentPower.", nameof(obj));
444+
445+
return CompareTo((ApparentPower)obj);
445446
}
446447

447448
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -452,7 +453,7 @@ public int CompareTo(object obj)
452453
#endif
453454
int CompareTo(ApparentPower other)
454455
{
455-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
456+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
456457
}
457458

458459
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -691,7 +692,7 @@ public static ApparentPower Parse(
691692
[CanBeNull] IFormatProvider provider)
692693
#endif
693694
{
694-
if (str == null) throw new ArgumentNullException("str");
695+
if (str == null) throw new ArgumentNullException(nameof(str));
695696

696697
#if WINDOWS_UWP
697698
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -819,7 +820,7 @@ public static ApparentPowerUnit ParseUnit(string str, [CanBeNull] string culture
819820
#endif
820821
static ApparentPowerUnit ParseUnit(string str, IFormatProvider provider = null)
821822
{
822-
if (str == null) throw new ArgumentNullException("str");
823+
if (str == null) throw new ArgumentNullException(nameof(str));
823824

824825
var unitSystem = UnitSystem.GetCached(provider);
825826
var unit = unitSystem.Parse<ApparentPowerUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/Area.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,10 @@ public static string GetAbbreviation(
736736

737737
public int CompareTo(object obj)
738738
{
739-
if (obj == null) throw new ArgumentNullException("obj");
740-
if (!(obj is Area)) throw new ArgumentException("Expected type Area.", "obj");
741-
return CompareTo((Area) obj);
739+
if(obj is null) throw new ArgumentNullException(nameof(obj));
740+
if(!(obj is Area)) throw new ArgumentException("Expected type Area.", nameof(obj));
741+
742+
return CompareTo((Area)obj);
742743
}
743744

744745
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -749,7 +750,7 @@ public int CompareTo(object obj)
749750
#endif
750751
int CompareTo(Area other)
751752
{
752-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
753+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
753754
}
754755

755756
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1006,7 +1007,7 @@ public static Area Parse(
10061007
[CanBeNull] IFormatProvider provider)
10071008
#endif
10081009
{
1009-
if (str == null) throw new ArgumentNullException("str");
1010+
if (str == null) throw new ArgumentNullException(nameof(str));
10101011

10111012
#if WINDOWS_UWP
10121013
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -1134,7 +1135,7 @@ public static AreaUnit ParseUnit(string str, [CanBeNull] string cultureName)
11341135
#endif
11351136
static AreaUnit ParseUnit(string str, IFormatProvider provider = null)
11361137
{
1137-
if (str == null) throw new ArgumentNullException("str");
1138+
if (str == null) throw new ArgumentNullException(nameof(str));
11381139

11391140
var unitSystem = UnitSystem.GetCached(provider);
11401141
var unit = unitSystem.Parse<AreaUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,10 @@ public static string GetAbbreviation(
340340

341341
public int CompareTo(object obj)
342342
{
343-
if (obj == null) throw new ArgumentNullException("obj");
344-
if (!(obj is AreaDensity)) throw new ArgumentException("Expected type AreaDensity.", "obj");
345-
return CompareTo((AreaDensity) obj);
343+
if(obj is null) throw new ArgumentNullException(nameof(obj));
344+
if(!(obj is AreaDensity)) throw new ArgumentException("Expected type AreaDensity.", nameof(obj));
345+
346+
return CompareTo((AreaDensity)obj);
346347
}
347348

348349
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -353,7 +354,7 @@ public int CompareTo(object obj)
353354
#endif
354355
int CompareTo(AreaDensity other)
355356
{
356-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
357+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
357358
}
358359

359360
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -586,7 +587,7 @@ public static AreaDensity Parse(
586587
[CanBeNull] IFormatProvider provider)
587588
#endif
588589
{
589-
if (str == null) throw new ArgumentNullException("str");
590+
if (str == null) throw new ArgumentNullException(nameof(str));
590591

591592
#if WINDOWS_UWP
592593
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -714,7 +715,7 @@ public static AreaDensityUnit ParseUnit(string str, [CanBeNull] string cultureNa
714715
#endif
715716
static AreaDensityUnit ParseUnit(string str, IFormatProvider provider = null)
716717
{
717-
if (str == null) throw new ArgumentNullException("str");
718+
if (str == null) throw new ArgumentNullException(nameof(str));
718719

719720
var unitSystem = UnitSystem.GetCached(provider);
720721
var unit = unitSystem.Parse<AreaDensityUnit>(str.Trim());

UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,10 @@ public static string GetAbbreviation(
505505

506506
public int CompareTo(object obj)
507507
{
508-
if (obj == null) throw new ArgumentNullException("obj");
509-
if (!(obj is AreaMomentOfInertia)) throw new ArgumentException("Expected type AreaMomentOfInertia.", "obj");
510-
return CompareTo((AreaMomentOfInertia) obj);
508+
if(obj is null) throw new ArgumentNullException(nameof(obj));
509+
if(!(obj is AreaMomentOfInertia)) throw new ArgumentException("Expected type AreaMomentOfInertia.", nameof(obj));
510+
511+
return CompareTo((AreaMomentOfInertia)obj);
511512
}
512513

513514
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
@@ -518,7 +519,7 @@ public int CompareTo(object obj)
518519
#endif
519520
int CompareTo(AreaMomentOfInertia other)
520521
{
521-
return AsBaseUnit().CompareTo(other.AsBaseUnit());
522+
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
522523
}
523524

524525
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -761,7 +762,7 @@ public static AreaMomentOfInertia Parse(
761762
[CanBeNull] IFormatProvider provider)
762763
#endif
763764
{
764-
if (str == null) throw new ArgumentNullException("str");
765+
if (str == null) throw new ArgumentNullException(nameof(str));
765766

766767
#if WINDOWS_UWP
767768
// Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -889,7 +890,7 @@ public static AreaMomentOfInertiaUnit ParseUnit(string str, [CanBeNull] string c
889890
#endif
890891
static AreaMomentOfInertiaUnit ParseUnit(string str, IFormatProvider provider = null)
891892
{
892-
if (str == null) throw new ArgumentNullException("str");
893+
if (str == null) throw new ArgumentNullException(nameof(str));
893894

894895
var unitSystem = UnitSystem.GetCached(provider);
895896
var unit = unitSystem.Parse<AreaMomentOfInertiaUnit>(str.Trim());

0 commit comments

Comments
 (0)