Skip to content

Commit

Permalink
Fix consistent whitespace of if expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
angularsen committed Feb 9, 2022
1 parent 38405dc commit ebd3275
Show file tree
Hide file tree
Showing 471 changed files with 3,803 additions and 4,141 deletions.
2 changes: 1 addition & 1 deletion CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override string Generate()
<dependencies>
<dependency id=""nanoFramework.CoreLibrary"" version=""{_mscorlibNuGetVersion}"" />");

if(NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name))
if (NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name))
{
Writer.WL($@"
<dependency id=""nanoFramework.System.Math"" version=""{_mathNuGetVersion}"" />");
Expand Down
2 changes: 1 addition & 1 deletion CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override string Generate()
<SpecificVersion>True</SpecificVersion>
</Reference>");

if(NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name))
if (NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name))
{
Writer.WL($@"
<Reference Include=""System.Math, Version={_versions.MathVersion}, Culture=neutral, PublicKeyToken=c07d481e9758c731"">
Expand Down
12 changes: 5 additions & 7 deletions CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class QuantityGenerator : GeneratorBase
public QuantityGenerator(Quantity quantity)
{
_quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
_unitEnumName = $"{quantity.Name}Unit";
_unitEnumName = $"{quantity.Name}Unit";
}

public override string Generate()
Expand Down Expand Up @@ -124,7 +124,7 @@ private void GenerateConversionProperties()
");
foreach (var unit in _quantity.Units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

Writer.WL($@"
Expand All @@ -149,7 +149,7 @@ private void GenerateStaticFactoryMethods()
");
foreach (var unit in _quantity.Units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

var valueParamName = unit.PluralName.ToLowerInvariant();
Expand Down Expand Up @@ -189,20 +189,18 @@ private void GenerateConversionMethods()
/// Convert to the unit representation <paramref name=""unit"" />.
/// </summary>
/// <returns>Value converted to the specified unit.</returns>
public {_quantity.BaseType} As({_unitEnumName} unit) => GetValueAs(unit);
public {_quantity.BaseType} As({_unitEnumName} unit) => GetValueAs(unit);
/// <summary>
/// Converts this Duration to another Duration with the unit representation <paramref name=""unit"" />.
/// </summary>
/// <returns>A Duration with the specified unit.</returns>
public {_quantity.Name} ToUnit({_unitEnumName} unit)
{{
var convertedValue = GetValueAs(unit);
return new {_quantity.Name}(convertedValue, unit);
}}
/// <summary>
/// Converts the current value + unit to the base unit.
/// This is typically the first step in converting from one unit to another.
Expand All @@ -227,7 +225,7 @@ private void GenerateConversionMethods()
private {_quantity.BaseType} GetValueAs({_unitEnumName} unit)
{{
if(Unit == unit)
if (Unit == unit)
return _value;
var baseUnitValue = GetValueInBaseUnit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class NumberTo{_quantityName}Extensions

foreach (var unit in _units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

Writer.WL(2, $@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class NumberTo{_quantityName}ExtensionsTests

foreach (var unit in _units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

Writer.WL(2, $@"
Expand Down
54 changes: 27 additions & 27 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void GenerateInstanceConstructors()
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
public {_quantity.Name}({_quantity.BaseType} value, {_unitEnumName} unit)
{{
if(unit == {_unitEnumName}.Undefined)
if (unit == {_unitEnumName}.Undefined)
throw new ArgumentException(""The quantity can not be created with an undefined unit."", nameof(unit));
");

Expand All @@ -206,7 +206,7 @@ private void GenerateInstanceConstructors()
/// <exception cref=""ArgumentException"">No unit was found for the given <see cref=""UnitSystem""/>.</exception>
public {_quantity.Name}({_valueType} value, UnitSystem unitSystem)
{{
if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem));
if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem));
var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits);
var firstUnitInfo = unitInfos.FirstOrDefault();
Expand Down Expand Up @@ -334,7 +334,7 @@ private void GenerateConversionProperties()
");
foreach (var unit in _quantity.Units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

Writer.WL($@"
Expand Down Expand Up @@ -369,7 +369,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter)

foreach(var unit in _quantity.Units)
{
if(unit.SingularName == _quantity.BaseUnit)
if (unit.SingularName == _quantity.BaseUnit)
continue;

var func = unit.FromBaseToUnitFunc.Replace("{x}", "quantity.Value");
Expand All @@ -378,15 +378,15 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter)
}

Writer.WL($@"
// Register in unit converter: BaseUnit <-> BaseUnit
unitConverter.SetConversionFunction<{_quantity.Name}>({_unitEnumName}.{_quantity.BaseUnit}, {_unitEnumName}.{_quantity.BaseUnit}, quantity => quantity);
// Register in unit converter: {_quantity.Name}Unit -> BaseUnit");

foreach(var unit in _quantity.Units)
{
if(unit.SingularName == _quantity.BaseUnit)
if (unit.SingularName == _quantity.BaseUnit)
continue;

var func = unit.FromUnitToBaseFunc.Replace("{x}", "quantity.Value");
Expand Down Expand Up @@ -448,7 +448,7 @@ private void GenerateStaticFactoryMethods()
");
foreach (var unit in _quantity.Units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

var valueParamName = unit.PluralName.ToLowerInvariant();
Expand Down Expand Up @@ -801,8 +801,8 @@ private void GenerateEqualityAndComparison()
/// <inheritdoc />
public int CompareTo(object obj)
{{
if(obj is null) throw new ArgumentNullException(nameof(obj));
if(!(obj is {_quantity.Name} obj{_quantity.Name})) throw new ArgumentException(""Expected type {_quantity.Name}."", nameof(obj));
if (obj is null) throw new ArgumentNullException(nameof(obj));
if (!(obj is {_quantity.Name} obj{_quantity.Name})) throw new ArgumentException(""Expected type {_quantity.Name}."", nameof(obj));
return CompareTo(obj{_quantity.Name});
}}
Expand All @@ -817,7 +817,7 @@ public int CompareTo({_quantity.Name} other)
/// <remarks>Consider using <see cref=""Equals({_quantity.Name}, double, ComparisonType)""/> for safely comparing floating point values.</remarks>
public override bool Equals(object obj)
{{
if(obj is null || !(obj is {_quantity.Name} obj{_quantity.Name}))
if (obj is null || !(obj is {_quantity.Name} obj{_quantity.Name}))
return false;
return Equals(obj{_quantity.Name});
Expand Down Expand Up @@ -872,7 +872,7 @@ public bool Equals({_quantity.Name} other)
/// <returns>True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.</returns>
public bool Equals({_quantity.Name} other, double tolerance, ComparisonType comparisonType)
{{
if(tolerance < 0)
if (tolerance < 0)
throw new ArgumentOutOfRangeException(""tolerance"", ""Tolerance must be greater than or equal to 0."");
double thisValue = (double)this.Value;
Expand Down Expand Up @@ -905,7 +905,7 @@ private void GenerateConversionMethods()
/// <returns>Value converted to the specified unit.</returns>
public double As({_unitEnumName} unit)
{{
if(Unit == unit)
if (Unit == unit)
return Convert.ToDouble(Value);
var converted = GetValueAs(unit);
Expand All @@ -915,13 +915,13 @@ public double As({_unitEnumName} unit)
/// <inheritdoc cref=""IQuantity.As(UnitSystem)""/>
public double As(UnitSystem unitSystem)
{{
if(unitSystem is null)
if (unitSystem is null)
throw new ArgumentNullException(nameof(unitSystem));
var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits);
var firstUnitInfo = unitInfos.FirstOrDefault();
if(firstUnitInfo == null)
if (firstUnitInfo == null)
throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
return As(firstUnitInfo.Value);
Expand All @@ -930,7 +930,7 @@ public double As(UnitSystem unitSystem)
/// <inheritdoc />
double IQuantity.As(Enum unit)
{{
if(!(unit is {_unitEnumName} unitAs{_unitEnumName}))
if (!(unit is {_unitEnumName} unitAs{_unitEnumName}))
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
return As(unitAs{_unitEnumName});
Expand All @@ -954,18 +954,18 @@ double IQuantity.As(Enum unit)
/// <returns>A {_quantity.Name} with the specified unit.</returns>
public {_quantity.Name} ToUnit({_unitEnumName} unit, UnitConverter unitConverter)
{{
if(Unit == unit)
if (Unit == unit)
{{
// Already in requested units.
return this;
}}
else if(unitConverter.TryGetConversionFunction((typeof({_quantity.Name}), Unit, typeof({_quantity.Name}), unit), out var conversionFunction))
else if (unitConverter.TryGetConversionFunction((typeof({_quantity.Name}), Unit, typeof({_quantity.Name}), unit), out var conversionFunction))
{{
// Direct conversion to requested unit found. Return the converted quantity.
var converted = conversionFunction(this);
return ({_quantity.Name})converted;
}}
else if(Unit != BaseUnit)
else if (Unit != BaseUnit)
{{
// Direct conversion to requested unit NOT found. Convert to BaseUnit, and then from BaseUnit to requested unit.
var inBaseUnits = ToUnit(BaseUnit);
Expand All @@ -980,7 +980,7 @@ double IQuantity.As(Enum unit)
/// <inheritdoc />
IQuantity IQuantity.ToUnit(Enum unit)
{{
if(!(unit is {_unitEnumName} unitAs{_unitEnumName}))
if (!(unit is {_unitEnumName} unitAs{_unitEnumName}))
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
return ToUnit(unitAs{_unitEnumName}, DefaultConversionFunctions);
Expand All @@ -989,7 +989,7 @@ IQuantity IQuantity.ToUnit(Enum unit)
/// <inheritdoc />
IQuantity IQuantity.ToUnit(Enum unit, UnitConverter unitConverter)
{{
if(!(unit is {_unitEnumName} unitAs{_unitEnumName}))
if (!(unit is {_unitEnumName} unitAs{_unitEnumName}))
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
return ToUnit(unitAs{_unitEnumName}, unitConverter);
Expand All @@ -998,13 +998,13 @@ IQuantity IQuantity.ToUnit(Enum unit, UnitConverter unitConverter)
/// <inheritdoc cref=""IQuantity.ToUnit(UnitSystem)""/>
public {_quantity.Name} ToUnit(UnitSystem unitSystem)
{{
if(unitSystem is null)
if (unitSystem is null)
throw new ArgumentNullException(nameof(unitSystem));
var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits);
var firstUnitInfo = unitInfos.FirstOrDefault();
if(firstUnitInfo == null)
if (firstUnitInfo == null)
throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
return ToUnit(firstUnitInfo.Value);
Expand Down Expand Up @@ -1189,15 +1189,15 @@ string IConvertible.ToString(IFormatProvider provider)
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
{{
if(conversionType == typeof({_quantity.Name}))
if (conversionType == typeof({_quantity.Name}))
return this;
else if(conversionType == typeof({_unitEnumName}))
else if (conversionType == typeof({_unitEnumName}))
return Unit;
else if(conversionType == typeof(QuantityType))
else if (conversionType == typeof(QuantityType))
return {_quantity.Name}.QuantityType;
else if(conversionType == typeof(QuantityInfo))
else if (conversionType == typeof(QuantityInfo))
return {_quantity.Name}.Info;
else if(conversionType == typeof(BaseDimensions))
else if (conversionType == typeof(BaseDimensions))
return {_quantity.Name}.BaseDimensions;
else
throw new InvalidCastException($""Converting {{typeof({_quantity.Name})}} to {{conversionType}} is not supported."");
Expand Down
16 changes: 8 additions & 8 deletions CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public abstract partial class {_quantity.Name}TestsBase : QuantityTestsBase
{{");
foreach (var unit in _quantity.Units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

Writer.WL($@"
Expand All @@ -110,7 +110,7 @@ public abstract partial class {_quantity.Name}TestsBase : QuantityTestsBase
// ReSharper disable VirtualMemberNeverOverriden.Global");
foreach (var unit in _quantity.Units)
{
if(unit.SkipConversionGeneration)
if (unit.SkipConversionGeneration)
continue;

Writer.WL($@"
Expand Down Expand Up @@ -151,14 +151,14 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit()
{{
var quantity = new {_quantity.Name}();
Assert.Equal(0, quantity.Value);");
if(_quantity.BaseType == "decimal") Writer.WL($@"
if (_quantity.BaseType == "decimal") Writer.WL($@"
Assert.Equal(0m, ((IDecimalQuantity)quantity).Value);");
Writer.WL($@"
Assert.Equal({_baseUnitFullName}, quantity.Unit);
}}
");
if(_quantity.BaseType == "double") Writer.WL($@"
if (_quantity.BaseType == "double") Writer.WL($@"
[Fact]
public void Ctor_WithInfinityValue_ThrowsArgumentException()
{{
Expand Down Expand Up @@ -240,7 +240,7 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
Writer.WL($@"
}}
");
if(_quantity.BaseType == "double") Writer.WL($@"
if (_quantity.BaseType == "double") Writer.WL($@"
[Fact]
public void From{_baseUnit.PluralName}_WithInfinityValue_ThrowsArgumentException()
{{
Expand Down Expand Up @@ -310,7 +310,7 @@ public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit({_unitEnumName}
var fromUnit = {_quantity.Name}.Units.FirstOrDefault(u => u != {_quantity.Name}.BaseUnit && u != {_unitEnumName}.Undefined);
// If there is only one unit for the quantity, we must use the base unit.
if(fromUnit == {_unitEnumName}.Undefined)
if (fromUnit == {_unitEnumName}.Undefined)
fromUnit = {_quantity.Name}.BaseUnit;
var quantity = {_quantity.Name}.From(3.0, fromUnit);
Expand Down Expand Up @@ -496,7 +496,7 @@ public void HasAtLeastOneAbbreviationSpecified()
var units = Enum.GetValues(typeof({_unitEnumName})).Cast<{_unitEnumName}>();
foreach(var unit in units)
{{
if(unit == {_unitEnumName}.Undefined)
if (unit == {_unitEnumName}.Undefined)
continue;
var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit);
Expand Down Expand Up @@ -748,7 +748,7 @@ public void GetHashCode_Equals()
}}
");

if(_quantity.GenerateArithmetic)
if (_quantity.GenerateArithmetic)
{
Writer.WL($@"
[Theory]
Expand Down
Loading

0 comments on commit ebd3275

Please sign in to comment.