Skip to content

Commit 92c5a2b

Browse files
committed
Remove TValueType from IQuantity
1 parent dbb9341 commit 92c5a2b

File tree

5 files changed

+17
-71
lines changed

5 files changed

+17
-71
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace UnitsNet
6565
Writer.WL(@$"
6666
[DataContract]
6767
public readonly partial struct {_quantity.Name} :
68-
{(_quantity.GenerateArithmetic ? "IArithmeticQuantity" : "IQuantity")}<{_quantity.Name}, {_unitEnumName}, {_quantity.ValueType}>,");
68+
{(_quantity.GenerateArithmetic ? "IArithmeticQuantity" : "IQuantity")}<{_quantity.Name}, {_unitEnumName}>,");
6969

7070
if (_quantity.ValueType == "decimal") Writer.WL(@$"
7171
IDecimalQuantity,");

UnitsNet.Tests/CustomCode/IQuantityTests.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,5 @@ public void ToUnit_GivenSIUnitSystem_ReturnsSIQuantity()
5757
Assert.Equal(0.0508, inSI.Value);
5858
Assert.Equal(LengthUnit.Meter, inSI.Unit);
5959
}
60-
61-
62-
[Fact]
63-
public void IQuantityTUnitDouble_Value_ReturnsDouble()
64-
{
65-
IQuantity<TemperatureUnit, double> doubleQuantity = Temperature.FromDegreesCelsius(1234.5);
66-
Assert.IsType<double>(doubleQuantity.Value);
67-
}
68-
69-
[Fact]
70-
public void IQuantityTUnitDouble_AsEnum_ReturnsDouble()
71-
{
72-
IQuantity<TemperatureUnit, double> doubleQuantity = Temperature.FromDegreesCelsius(1234.5);
73-
Assert.IsType<double>(doubleQuantity.As(TemperatureUnit.Kelvin));
74-
}
75-
76-
[Fact]
77-
public void IQuantityTUnitDouble_AsUnitSystem_ReturnsDouble()
78-
{
79-
IQuantity<TemperatureUnit, double> doubleQuantity = Temperature.FromDegreesCelsius(1234.5);
80-
Assert.IsType<double>(doubleQuantity.As(UnitSystem.SI));
81-
}
8260
}
8361
}

UnitsNet.Tests/QuantityTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public void GetHashCodeForDifferentQuantitiesWithSameValuesAreNotEqual()
3131
public void Equals_IGenericEquatableQuantity(string q1String, string q2String, string toleranceString, bool expectedEqual)
3232
{
3333
// This interfaces implements .NET generic math interfaces.
34-
IQuantity<Length, LengthUnit, double> q1 = ParseLength(q1String);
35-
IQuantity<Length, LengthUnit, double> q2 = ParseLength(q2String);
36-
IQuantity<Length, LengthUnit, double> tolerance = ParseLength(toleranceString);
34+
IQuantity<Length, LengthUnit> q1 = ParseLength(q1String);
35+
IQuantity<Length, LengthUnit> q2 = ParseLength(q2String);
36+
IQuantity<Length, LengthUnit> tolerance = ParseLength(toleranceString);
3737

3838
Assert.Equal(expectedEqual, q1.Equals(q2, tolerance));
3939
}
@@ -88,9 +88,9 @@ public void Equals_IQuantity_ToleranceIsDifferentType_Throws()
8888
[Fact]
8989
public void Equals_GenericEquatableIQuantity_OtherIsNull_ReturnsFalse()
9090
{
91-
IQuantity<Length, LengthUnit, double> q1 = ParseLength("10 m");
92-
IQuantity<Length, LengthUnit, double>? q2 = null;
93-
IQuantity<Length, LengthUnit, double> tolerance = ParseLength("0.1 m");
91+
IQuantity<Length, LengthUnit> q1 = ParseLength("10 m");
92+
IQuantity<Length, LengthUnit>? q2 = null;
93+
IQuantity<Length, LengthUnit> tolerance = ParseLength("0.1 m");
9494

9595
Assert.False(q1.Equals(q2, tolerance));
9696
}

UnitsNet/IArithmeticQuantity.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,21 @@
77
namespace UnitsNet;
88

99
/// <summary>
10-
/// An <see cref="IQuantity{TSelf, TUnitType, TValueType}"/> that (in .NET 7+) implements generic math interfaces for arithmetic operations.
10+
/// An <see cref="IQuantity{TSelf, TUnitType}"/> that (in .NET 7+) implements generic math interfaces for arithmetic operations.
1111
/// </summary>
1212
/// <typeparam name="TSelf">The type itself, for the CRT pattern.</typeparam>
1313
/// <typeparam name="TUnitType">The underlying unit enum type.</typeparam>
14-
/// <typeparam name="TValueType">The underlying value type for internal representation.</typeparam>
15-
public interface IArithmeticQuantity<TSelf, TUnitType, TValueType> : IQuantity<TSelf, TUnitType, TValueType>
14+
public interface IArithmeticQuantity<TSelf, TUnitType> : IQuantity<TSelf, TUnitType>
1615
#if NET7_0_OR_GREATER
1716
, IAdditionOperators<TSelf, TSelf, TSelf>
1817
, IAdditiveIdentity<TSelf, TSelf>
1918
, ISubtractionOperators<TSelf, TSelf, TSelf>
20-
, IMultiplyOperators<TSelf, TValueType, TSelf>
21-
, IDivisionOperators<TSelf, TValueType, TSelf>
19+
, IMultiplyOperators<TSelf, double, TSelf>
20+
, IDivisionOperators<TSelf, double, TSelf>
2221
, IUnaryNegationOperators<TSelf, TSelf>
2322
#endif
24-
where TSelf : IArithmeticQuantity<TSelf, TUnitType, TValueType>
23+
where TSelf : IArithmeticQuantity<TSelf, TUnitType>
2524
where TUnitType : Enum
26-
where TValueType : struct
27-
#if NET7_0_OR_GREATER
28-
, INumber<TValueType>
29-
#endif
3025
{
3126
#if NET7_0_OR_GREATER
3227
/// <summary>

UnitsNet/IQuantity.cs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -142,49 +142,22 @@ public interface IQuantity<TUnitType> : IQuantity
142142
new IQuantity<TUnitType> ToUnit(UnitSystem unitSystem);
143143
}
144144

145-
/// <summary>
146-
/// A quantity backed by a particular value type with a stronger typed interface where the unit enum type is known, to avoid passing in the
147-
/// wrong unit enum type and not having to cast from <see cref="Enum"/>.
148-
/// </summary>
149-
/// <typeparam name="TUnitType">The unit type of the quantity.</typeparam>
150-
/// <typeparam name="TValueType">The value type of the quantity.</typeparam>
151-
public interface IQuantity<TUnitType, out TValueType> : IQuantity<TUnitType>
152-
where TUnitType : Enum
153-
#if NET7_0_OR_GREATER
154-
where TValueType : INumber<TValueType>
155-
#else
156-
where TValueType : struct
157-
#endif
158-
{
159-
/// <summary>
160-
/// Convert to a unit representation <typeparamref name="TUnitType"/>.
161-
/// </summary>
162-
/// <returns>Value converted to the specified unit.</returns>
163-
new TValueType As(TUnitType unit);
164-
}
165-
166145
/// <summary>
167146
/// An <see cref="IQuantity{TUnitType}"/> that (in .NET 7+) implements generic math interfaces for equality, comparison and parsing.
168147
/// </summary>
169148
/// <typeparam name="TSelf">The type itself, for the CRT pattern.</typeparam>
170149
/// <typeparam name="TUnitType">The underlying unit enum type.</typeparam>
171-
/// <typeparam name="TValueType">The underlying value type for internal representation.</typeparam>
172150
#if NET7_0_OR_GREATER
173-
public interface IQuantity<TSelf, TUnitType, out TValueType>
174-
: IQuantity<TUnitType, TValueType>
151+
public interface IQuantity<TSelf, TUnitType>
152+
: IQuantity<TUnitType>
175153
, IComparisonOperators<TSelf, TSelf, bool>
176154
, IParsable<TSelf>
177155
#else
178-
public interface IQuantity<in TSelf, TUnitType, out TValueType>
179-
: IQuantity<TUnitType, TValueType>
156+
public interface IQuantity<in TSelf, TUnitType>
157+
: IQuantity<TUnitType>
180158
#endif
181-
where TSelf : IQuantity<TSelf, TUnitType, TValueType>
159+
where TSelf : IQuantity<TSelf, TUnitType>
182160
where TUnitType : Enum
183-
#if NET7_0_OR_GREATER
184-
where TValueType : INumber<TValueType>
185-
#else
186-
where TValueType : struct
187-
#endif
188161
{
189162
/// <summary>
190163
/// <para>

0 commit comments

Comments
 (0)