Skip to content

Commit 7398448

Browse files
committed
♻️ Code cleanup
1 parent 564e0ee commit 7398448

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

UnitsNet/CustomCode/Quantities/Length.extra.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ public partial struct Length
1919
/// <returns>The inverse of this unit as <see cref="ReciprocalLength"/>.</returns>
2020
public ReciprocalLength Inverse()
2121
{
22-
if (Meters == 0.0)
23-
return new ReciprocalLength(0.0, ReciprocalLengthUnit.InverseMeter);
24-
25-
return new ReciprocalLength(1 / Meters, ReciprocalLengthUnit.InverseMeter);
22+
return Meters == 0.0
23+
? new ReciprocalLength(0.0, ReciprocalLengthUnit.InverseMeter)
24+
: new ReciprocalLength(1 / Meters, ReciprocalLengthUnit.InverseMeter);
2625
}
2726

2827
/// <summary>
@@ -262,8 +261,8 @@ public string ToArchitecturalString(int fractionDenominator)
262261
throw new ArgumentOutOfRangeException(nameof(fractionDenominator), "Denominator for fractional inch must be greater than zero.");
263262
}
264263

265-
var inchTrunc = (int)Math.Truncate(this.Inches);
266-
var numerator = (int)Math.Round((this.Inches - inchTrunc) * fractionDenominator);
264+
var inchTrunc = (int)Math.Truncate(Inches);
265+
var numerator = (int)Math.Round((Inches - inchTrunc) * fractionDenominator);
267266

268267
if (numerator == fractionDenominator)
269268
{
@@ -280,7 +279,7 @@ public string ToArchitecturalString(int fractionDenominator)
280279

281280
if (numerator > 0)
282281
{
283-
int greatestCommonDivisor(int a, int b)
282+
int GreatestCommonDivisor(int a, int b)
284283
{
285284
while (a != 0 && b != 0)
286285
{
@@ -293,7 +292,7 @@ int greatestCommonDivisor(int a, int b)
293292
return a | b;
294293
}
295294

296-
int gcd = greatestCommonDivisor((int)Math.Abs(numerator), fractionDenominator);
295+
int gcd = GreatestCommonDivisor(numerator, fractionDenominator);
297296

298297
if (inchPart.Length > 0)
299298
{
@@ -305,12 +304,12 @@ int greatestCommonDivisor(int a, int b)
305304

306305
inchPart.Append('"');
307306

308-
if (this.Feet == 0)
307+
if (Feet == 0)
309308
{
310309
return inchPart.ToString();
311310
}
312311

313-
return $"{this.Feet}' - {inchPart}";
312+
return $"{Feet}' - {inchPart}";
314313
}
315314
}
316315
}

0 commit comments

Comments
 (0)