Skip to content

Commit 911b480

Browse files
committed
Remove IValueQuantity
1 parent 5dc3dd5 commit 911b480

File tree

7 files changed

+3
-165
lines changed

7 files changed

+3
-165
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,15 +1068,6 @@ double IQuantity.As(Enum unit)
10681068
return (double)As(typedUnit);
10691069
}}
10701070
1071-
/// <inheritdoc />
1072-
{_quantity.ValueType} IValueQuantity<{_quantity.ValueType}>.As(Enum unit)
1073-
{{
1074-
if (!(unit is {_unitEnumName} typedUnit))
1075-
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
1076-
1077-
return As(typedUnit);
1078-
}}
1079-
10801071
/// <summary>
10811072
/// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation <paramref name=""unit"" />.
10821073
/// </summary>
@@ -1206,18 +1197,6 @@ IQuantity IQuantity.ToUnit(Enum unit)
12061197
/// <inheritdoc />
12071198
IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
12081199
1209-
/// <inheritdoc />
1210-
IValueQuantity<{_quantity.ValueType}> IValueQuantity<{_quantity.ValueType}>.ToUnit(Enum unit)
1211-
{{
1212-
if (unit is not {_unitEnumName} typedUnit)
1213-
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
1214-
1215-
return ToUnit(typedUnit);
1216-
}}
1217-
1218-
/// <inheritdoc />
1219-
IValueQuantity<{_quantity.ValueType}> IValueQuantity<{_quantity.ValueType}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
1220-
12211200
#endregion
12221201
");
12231202
}

CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ public abstract partial class {_quantity.Name}TestsBase : QuantityTestsBase
162162
public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit()
163163
{{
164164
var quantity = new {_quantity.Name}();
165-
Assert.Equal(0, quantity.Value);");
166-
if (_quantity.ValueType == "decimal") Writer.WL(@"
167-
Assert.Equal(0m, ((IValueQuantity<decimal>)quantity).Value);");
168-
Writer.WL($@"
165+
Assert.Equal(0, quantity.Value);
169166
Assert.Equal({_baseUnitFullName}, quantity.Unit);
170167
}}
171168
");

UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,7 @@ public override void WriteJson(JsonWriter writer, IQuantity? quantity, JsonSeria
7979

8080
// write the 'Value' using the actual type
8181
writer.WritePropertyName(ValueProperty);
82-
if (quantity is IValueQuantity<decimal> decimalQuantity)
83-
{
84-
// cannot use `writer.WriteValue(decimalQuantity.Value)`: there is a hidden EnsureDecimalPlace(..) method call inside it that converts '123' to '123.0'
85-
writer.WriteRawValue(decimalQuantity.Value.ToString(CultureInfo.InvariantCulture));
86-
}
87-
else
88-
{
89-
writer.WriteValue((double)quantity.Value);
90-
}
82+
writer.WriteValue((double)quantity.Value);
9183

9284
// write the 'Unit' abbreviation
9385
writer.WritePropertyName(UnitProperty);

UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,6 @@ protected ValueUnit ConvertIQuantity(IQuantity quantity)
178178
{
179179
quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
180180

181-
if (quantity is IValueQuantity<decimal> d)
182-
{
183-
return new ExtendedValueUnit
184-
{
185-
Unit = $"{quantity.QuantityInfo.UnitType.Name}.{quantity.Unit}",
186-
// The type of "Value" is still double
187-
Value = (double)quantity.Value,
188-
ValueString = d.Value.ToString(CultureInfo.InvariantCulture),
189-
ValueType = "decimal"
190-
};
191-
}
192-
193181
return new ValueUnit {Value = (double)quantity.Value, Unit = $"{quantity.QuantityInfo.UnitType.Name}.{quantity.Unit}"};
194182
}
195183

UnitsNet.Tests/IValueQuantityTests.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

UnitsNet/IQuantity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public interface IQuantity<TUnitType> : IQuantity
148148
/// </summary>
149149
/// <typeparam name="TUnitType">The unit type of the quantity.</typeparam>
150150
/// <typeparam name="TValueType">The value type of the quantity.</typeparam>
151-
public interface IQuantity<TUnitType, out TValueType> : IQuantity<TUnitType>, IValueQuantity<TValueType>
151+
public interface IQuantity<TUnitType, out TValueType> : IQuantity<TUnitType>
152152
where TUnitType : Enum
153153
#if NET7_0_OR_GREATER
154154
where TValueType : INumber<TValueType>

UnitsNet/IValueQuantity.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)