Skip to content

Commit 6fd3a85

Browse files
committed
Remove conditional compilation
1 parent 40bbd6f commit 6fd3a85

File tree

7 files changed

+15
-49
lines changed

7 files changed

+15
-49
lines changed

CodeGen/Generators/UnitsNetGen/NumberExtensionsGenerator.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ public string Generate()
2424
Writer.WL(
2525
$@"
2626
using System;
27-
28-
#if NET7_0_OR_GREATER
2927
using System.Numerics;
30-
#endif
3128
3229
#nullable enable
3330
@@ -50,10 +47,7 @@ public static class NumberTo{_quantityName}Extensions
5047
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit.ObsoleteText));
5148

5249
Writer.WL(2, $@"public static {_quantityName} {unit.PluralName}<T>(this T value)
53-
where T : notnull
54-
#if NET7_0_OR_GREATER
55-
, INumber<T>
56-
#endif
50+
where T : notnull, INumber<T>
5751
=> {_quantityName}.From{unit.PluralName}(Convert.ToDouble(value));
5852
");
5953
}

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ public string Generate()
3838
using System.Diagnostics.CodeAnalysis;
3939
using System.Globalization;
4040
using System.Linq;");
41-
if (_quantity.Relations.Any(r => r.Operator is "*" or "/"))
42-
Writer.WL(@"#if NET7_0_OR_GREATER
43-
using System.Numerics;
44-
#endif");
41+
Writer.WLCondition(_quantity.Relations.Any(r => r.Operator is "*" or "/"),
42+
@"using System.Numerics;");
4543
Writer.WL(@"using System.Runtime.Serialization;
4644
using UnitsNet.InternalHelpers;
4745
using UnitsNet.Units;
@@ -69,33 +67,25 @@ namespace UnitsNet
6967
public readonly partial struct {_quantity.Name} :
7068
{(_quantity.GenerateArithmetic ? "IArithmeticQuantity" : "IQuantity")}<{_quantity.Name}, {_unitEnumName}>,");
7169

72-
if (_quantity.Relations.Any(r => r.Operator is "*" or "/"))
70+
foreach (var relation in _quantity.Relations)
7371
{
74-
Writer.WL(@$"
75-
#if NET7_0_OR_GREATER");
76-
foreach (var relation in _quantity.Relations)
72+
if (relation.LeftQuantity == _quantity)
7773
{
78-
if (relation.LeftQuantity == _quantity)
74+
switch (relation.Operator)
7975
{
80-
switch (relation.Operator)
81-
{
82-
case "*":
83-
Writer.W(@"
76+
case "*":
77+
Writer.W(@"
8478
IMultiplyOperators");
85-
break;
86-
case "/":
87-
Writer.W(@"
79+
break;
80+
case "/":
81+
Writer.W(@"
8882
IDivisionOperators");
89-
break;
90-
default:
91-
continue;
92-
}
93-
Writer.WL($"<{relation.LeftQuantity.Name}, {relation.RightQuantity.Name}, {relation.ResultQuantity.Name}>,");
83+
break;
84+
default:
85+
continue;
9486
}
87+
Writer.WL($"<{relation.LeftQuantity.Name}, {relation.RightQuantity.Name}, {relation.ResultQuantity.Name}>,");
9588
}
96-
97-
Writer.WL(@$"
98-
#endif");
9989
}
10090

10191
Writer.WL(@$"

UnitsNet.Tests/GenericMathExtensionsTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4-
#if NET7_0_OR_GREATER
54
using UnitsNet.GenericMath;
65
using Xunit;
76

@@ -25,5 +24,3 @@ public void CanCalcAverage_ForQuantitiesWithDoubleValueType()
2524
Assert.Equal(Length.FromCentimeters(150), values.Average());
2625
}
2726
}
28-
29-
#endif

UnitsNet.Tests/Serialization/CustomSerializationTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace UnitsNet.Tests.Serialization;
88

99
public class CustomSerializationTests
1010
{
11-
#if NET7_0_OR_GREATER
1211
private record QuantityDto(double Value, string QuantityName, string UnitName);
1312

1413
/// <summary>
@@ -48,5 +47,4 @@ public void CanMapToJsonAndBackViaCustomDto()
4847
Assert.Equal(5, deserializedQuantity!.Value);
4948
Assert.Equal(LengthUnit.Centimeter, deserializedQuantity.Unit);
5049
}
51-
#endif
5250
}

UnitsNet/GenericMath/GenericMathExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4-
#if NET7_0_OR_GREATER
54
using System.Collections.Generic;
65
using System.Linq;
76
using System.Numerics;
@@ -65,4 +64,3 @@ public static T Average<T>(this IEnumerable<T> source)
6564
return result.value / result.count;
6665
}
6766
}
68-
#endif

UnitsNet/IArithmeticQuantity.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@ namespace UnitsNet;
1212
/// <typeparam name="TSelf">The type itself, for the CRT pattern.</typeparam>
1313
/// <typeparam name="TUnitType">The underlying unit enum type.</typeparam>
1414
public interface IArithmeticQuantity<TSelf, TUnitType> : IQuantity<TSelf, TUnitType>
15-
#if NET7_0_OR_GREATER
1615
, IAdditionOperators<TSelf, TSelf, TSelf>
1716
, IAdditiveIdentity<TSelf, TSelf>
1817
, ISubtractionOperators<TSelf, TSelf, TSelf>
1918
, IMultiplyOperators<TSelf, double, TSelf>
2019
, IDivisionOperators<TSelf, double, TSelf>
2120
, IUnaryNegationOperators<TSelf, TSelf>
22-
#endif
2321
where TSelf : IArithmeticQuantity<TSelf, TUnitType>
2422
where TUnitType : Enum
2523
{
26-
#if NET7_0_OR_GREATER
2724
/// <summary>
2825
/// The zero value of this quantity.
2926
/// </summary>
3027
static abstract TSelf Zero { get; }
31-
#endif
3228
}

UnitsNet/IQuantity.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
using System;
55
using System.Globalization;
6-
#if NET7_0_OR_GREATER
76
using System.Numerics;
8-
#endif
97
using UnitsNet.Units;
108

119
namespace UnitsNet
@@ -147,15 +145,10 @@ public interface IQuantity<TUnitType> : IQuantity
147145
/// </summary>
148146
/// <typeparam name="TSelf">The type itself, for the CRT pattern.</typeparam>
149147
/// <typeparam name="TUnitType">The underlying unit enum type.</typeparam>
150-
#if NET7_0_OR_GREATER
151148
public interface IQuantity<TSelf, TUnitType>
152149
: IQuantity<TUnitType>
153150
, IComparisonOperators<TSelf, TSelf, bool>
154151
, IParsable<TSelf>
155-
#else
156-
public interface IQuantity<in TSelf, TUnitType>
157-
: IQuantity<TUnitType>
158-
#endif
159152
where TSelf : IQuantity<TSelf, TUnitType>
160153
where TUnitType : Enum
161154
{

0 commit comments

Comments
 (0)