@@ -183,7 +183,7 @@ private void GenerateInstanceConstructors()
183
183
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
184
184
public { _quantity . Name } ({ _quantity . BaseType } value, { _unitEnumName } unit)
185
185
{{
186
- if(unit == { _unitEnumName } .Undefined)
186
+ if (unit == { _unitEnumName } .Undefined)
187
187
throw new ArgumentException(""The quantity can not be created with an undefined unit."", nameof(unit));
188
188
" ) ;
189
189
@@ -206,7 +206,7 @@ private void GenerateInstanceConstructors()
206
206
/// <exception cref=""ArgumentException"">No unit was found for the given <see cref=""UnitSystem""/>.</exception>
207
207
public { _quantity . Name } ({ _valueType } value, UnitSystem unitSystem)
208
208
{{
209
- if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem));
209
+ if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem));
210
210
211
211
var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits);
212
212
var firstUnitInfo = unitInfos.FirstOrDefault();
@@ -334,7 +334,7 @@ private void GenerateConversionProperties()
334
334
" ) ;
335
335
foreach ( var unit in _quantity . Units )
336
336
{
337
- if ( unit . SkipConversionGeneration )
337
+ if ( unit . SkipConversionGeneration )
338
338
continue ;
339
339
340
340
Writer . WL ( $@ "
@@ -369,7 +369,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter)
369
369
370
370
foreach ( var unit in _quantity . Units )
371
371
{
372
- if ( unit . SingularName == _quantity . BaseUnit )
372
+ if ( unit . SingularName == _quantity . BaseUnit )
373
373
continue ;
374
374
375
375
var func = unit . FromBaseToUnitFunc . Replace ( "{x}" , "quantity.Value" ) ;
@@ -378,15 +378,15 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter)
378
378
}
379
379
380
380
Writer . WL ( $@ "
381
-
381
+
382
382
// Register in unit converter: BaseUnit <-> BaseUnit
383
383
unitConverter.SetConversionFunction<{ _quantity . Name } >({ _unitEnumName } .{ _quantity . BaseUnit } , { _unitEnumName } .{ _quantity . BaseUnit } , quantity => quantity);
384
384
385
385
// Register in unit converter: { _quantity . Name } Unit -> BaseUnit" ) ;
386
386
387
387
foreach ( var unit in _quantity . Units )
388
388
{
389
- if ( unit . SingularName == _quantity . BaseUnit )
389
+ if ( unit . SingularName == _quantity . BaseUnit )
390
390
continue ;
391
391
392
392
var func = unit . FromUnitToBaseFunc . Replace ( "{x}" , "quantity.Value" ) ;
@@ -448,7 +448,7 @@ private void GenerateStaticFactoryMethods()
448
448
" ) ;
449
449
foreach ( var unit in _quantity . Units )
450
450
{
451
- if ( unit . SkipConversionGeneration )
451
+ if ( unit . SkipConversionGeneration )
452
452
continue;
453
453
454
454
var valueParamName = unit. PluralName . ToLowerInvariant ( ) ;
@@ -801,8 +801,8 @@ private void GenerateEqualityAndComparison()
801
801
/// <inheritdoc />
802
802
public int CompareTo(object obj)
803
803
{{
804
- if(obj is null) throw new ArgumentNullException(nameof(obj));
805
- if(!(obj is { _quantity . Name } obj{ _quantity . Name } )) throw new ArgumentException(""Expected type { _quantity . Name } ."", nameof(obj));
804
+ if (obj is null) throw new ArgumentNullException(nameof(obj));
805
+ if (!(obj is { _quantity . Name } obj{ _quantity . Name } )) throw new ArgumentException(""Expected type { _quantity . Name } ."", nameof(obj));
806
806
807
807
return CompareTo(obj{ _quantity . Name } );
808
808
}}
@@ -817,7 +817,7 @@ public int CompareTo({_quantity.Name} other)
817
817
/// <remarks>Consider using <see cref=""Equals({ _quantity . Name } , double, ComparisonType)""/> for safely comparing floating point values.</remarks>
818
818
public override bool Equals(object obj)
819
819
{{
820
- if(obj is null || !(obj is { _quantity . Name } obj{ _quantity . Name } ))
820
+ if (obj is null || !(obj is { _quantity . Name } obj{ _quantity . Name } ))
821
821
return false;
822
822
823
823
return Equals(obj{ _quantity . Name } );
@@ -872,7 +872,7 @@ public bool Equals({_quantity.Name} other)
872
872
/// <returns>True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.</returns>
873
873
public bool Equals({ _quantity . Name } other, double tolerance, ComparisonType comparisonType)
874
874
{{
875
- if(tolerance < 0)
875
+ if (tolerance < 0)
876
876
throw new ArgumentOutOfRangeException(""tolerance"", ""Tolerance must be greater than or equal to 0."");
877
877
878
878
double thisValue = (double)this.Value;
@@ -905,7 +905,7 @@ private void GenerateConversionMethods()
905
905
/// <returns>Value converted to the specified unit.</returns>
906
906
public double As({ _unitEnumName } unit)
907
907
{{
908
- if(Unit == unit)
908
+ if (Unit == unit)
909
909
return Convert.ToDouble(Value);
910
910
911
911
var converted = GetValueAs(unit);
@@ -915,13 +915,13 @@ public double As({_unitEnumName} unit)
915
915
/// <inheritdoc cref=""IQuantity.As(UnitSystem)""/>
916
916
public double As(UnitSystem unitSystem)
917
917
{{
918
- if(unitSystem is null)
918
+ if (unitSystem is null)
919
919
throw new ArgumentNullException(nameof(unitSystem));
920
920
921
921
var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits);
922
922
923
923
var firstUnitInfo = unitInfos.FirstOrDefault();
924
- if(firstUnitInfo == null)
924
+ if (firstUnitInfo == null)
925
925
throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
926
926
927
927
return As(firstUnitInfo.Value);
@@ -930,7 +930,7 @@ public double As(UnitSystem unitSystem)
930
930
/// <inheritdoc />
931
931
double IQuantity.As(Enum unit)
932
932
{{
933
- if(!(unit is { _unitEnumName } unitAs{ _unitEnumName } ))
933
+ if (!(unit is { _unitEnumName } unitAs{ _unitEnumName } ))
934
934
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({ _unitEnumName } )}} is supported."", nameof(unit));
935
935
936
936
return As(unitAs{ _unitEnumName } );
@@ -954,18 +954,18 @@ double IQuantity.As(Enum unit)
954
954
/// <returns>A { _quantity . Name } with the specified unit.</returns>
955
955
public { _quantity . Name } ToUnit({ _unitEnumName } unit, UnitConverter unitConverter)
956
956
{{
957
- if(Unit == unit)
957
+ if (Unit == unit)
958
958
{{
959
959
// Already in requested units.
960
960
return this;
961
961
}}
962
- else if(unitConverter.TryGetConversionFunction((typeof({ _quantity . Name } ), Unit, typeof({ _quantity . Name } ), unit), out var conversionFunction))
962
+ else if (unitConverter.TryGetConversionFunction((typeof({ _quantity . Name } ), Unit, typeof({ _quantity . Name } ), unit), out var conversionFunction))
963
963
{{
964
964
// Direct conversion to requested unit found. Return the converted quantity.
965
965
var converted = conversionFunction(this);
966
966
return ({ _quantity . Name } )converted;
967
967
}}
968
- else if(Unit != BaseUnit)
968
+ else if (Unit != BaseUnit)
969
969
{{
970
970
// Direct conversion to requested unit NOT found. Convert to BaseUnit, and then from BaseUnit to requested unit.
971
971
var inBaseUnits = ToUnit(BaseUnit);
@@ -980,7 +980,7 @@ double IQuantity.As(Enum unit)
980
980
/// <inheritdoc />
981
981
IQuantity IQuantity.ToUnit(Enum unit)
982
982
{{
983
- if(!(unit is { _unitEnumName } unitAs{ _unitEnumName } ))
983
+ if (!(unit is { _unitEnumName } unitAs{ _unitEnumName } ))
984
984
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({ _unitEnumName } )}} is supported."", nameof(unit));
985
985
986
986
return ToUnit(unitAs{ _unitEnumName } , DefaultConversionFunctions);
@@ -989,7 +989,7 @@ IQuantity IQuantity.ToUnit(Enum unit)
989
989
/// <inheritdoc />
990
990
IQuantity IQuantity.ToUnit(Enum unit, UnitConverter unitConverter)
991
991
{{
992
- if(!(unit is { _unitEnumName } unitAs{ _unitEnumName } ))
992
+ if (!(unit is { _unitEnumName } unitAs{ _unitEnumName } ))
993
993
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({ _unitEnumName } )}} is supported."", nameof(unit));
994
994
995
995
return ToUnit(unitAs{ _unitEnumName } , unitConverter);
@@ -998,13 +998,13 @@ IQuantity IQuantity.ToUnit(Enum unit, UnitConverter unitConverter)
998
998
/// <inheritdoc cref=""IQuantity.ToUnit(UnitSystem)""/>
999
999
public { _quantity . Name } ToUnit(UnitSystem unitSystem)
1000
1000
{{
1001
- if(unitSystem is null)
1001
+ if (unitSystem is null)
1002
1002
throw new ArgumentNullException(nameof(unitSystem));
1003
1003
1004
1004
var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits);
1005
1005
1006
1006
var firstUnitInfo = unitInfos.FirstOrDefault();
1007
- if(firstUnitInfo == null)
1007
+ if (firstUnitInfo == null)
1008
1008
throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
1009
1009
1010
1010
return ToUnit(firstUnitInfo.Value);
@@ -1189,15 +1189,15 @@ string IConvertible.ToString(IFormatProvider provider)
1189
1189
1190
1190
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
1191
1191
{{
1192
- if(conversionType == typeof({ _quantity . Name } ))
1192
+ if (conversionType == typeof({ _quantity . Name } ))
1193
1193
return this;
1194
- else if(conversionType == typeof({ _unitEnumName } ))
1194
+ else if (conversionType == typeof({ _unitEnumName } ))
1195
1195
return Unit;
1196
- else if(conversionType == typeof(QuantityType))
1196
+ else if (conversionType == typeof(QuantityType))
1197
1197
return { _quantity . Name } .QuantityType;
1198
- else if(conversionType == typeof(QuantityInfo))
1198
+ else if (conversionType == typeof(QuantityInfo))
1199
1199
return { _quantity . Name } .Info;
1200
- else if(conversionType == typeof(BaseDimensions))
1200
+ else if (conversionType == typeof(BaseDimensions))
1201
1201
return { _quantity . Name } .BaseDimensions;
1202
1202
else
1203
1203
throw new InvalidCastException($""Converting {{typeof({ _quantity . Name } )}} to {{conversionType}} is not supported."");
0 commit comments