Skip to content

Commit dbb9341

Browse files
committed
Remove IValueQuantity
1 parent b8a94dc commit dbb9341

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
@@ -948,15 +948,6 @@ double IQuantity.As(Enum unit)
948948
return (double)As(typedUnit);
949949
}}
950950
951-
/// <inheritdoc />
952-
{_quantity.ValueType} IValueQuantity<{_quantity.ValueType}>.As(Enum unit)
953-
{{
954-
if (!(unit is {_unitEnumName} typedUnit))
955-
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
956-
957-
return As(typedUnit);
958-
}}
959-
960951
/// <summary>
961952
/// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation <paramref name=""unit"" />.
962953
/// </summary>
@@ -1086,18 +1077,6 @@ IQuantity IQuantity.ToUnit(Enum unit)
10861077
/// <inheritdoc />
10871078
IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
10881079
1089-
/// <inheritdoc />
1090-
IValueQuantity<{_quantity.ValueType}> IValueQuantity<{_quantity.ValueType}>.ToUnit(Enum unit)
1091-
{{
1092-
if (unit is not {_unitEnumName} typedUnit)
1093-
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
1094-
1095-
return ToUnit(typedUnit);
1096-
}}
1097-
1098-
/// <inheritdoc />
1099-
IValueQuantity<{_quantity.ValueType}> IValueQuantity<{_quantity.ValueType}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
1100-
11011080
#endregion
11021081
");
11031082
}

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)