Skip to content

Commit 77ada0e

Browse files
authored
refactor: Remove obsolete FromQuantityInfo method (#1574)
Fixup of #1555
1 parent 5131d24 commit 77ada0e

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

UnitsNet.Tests/QuantityTest.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void TryFrom_GivenNullUnit_ReturnsFalse()
3838
Enum? nullUnit = null;
3939
Assert.False(Quantity.TryFrom(1, nullUnit, out IQuantity? _));
4040
}
41-
41+
4242
[Fact]
4343
public void TryFrom_GivenUnknownUnitType_ReturnsFalse()
4444
{
@@ -53,14 +53,6 @@ public void From_GivenValueAndUnit_ReturnsQuantity()
5353
Assert.Equal(Pressure.FromMegabars(3), Quantity.From(3, PressureUnit.Megabar));
5454
}
5555

56-
[Fact]
57-
public void FromQuantityInfo_ReturnsQuantityWithBaseUnit()
58-
{
59-
IQuantity quantity = Quantity.FromQuantityInfo(Length.Info, 1);
60-
Assert.Equal(1, quantity.Value);
61-
Assert.Equal(Length.BaseUnit, quantity.Unit);
62-
}
63-
6456
[Fact]
6557
public void ByName_GivenLength_ReturnsQuantityInfoForLength()
6658
{
@@ -143,7 +135,7 @@ public void Parse_WithDefaultCulture_ReturnsQuantity(double value, string format
143135
Type targetType = expectedQuantity.QuantityInfo.QuantityType;
144136

145137
IQuantity parsedQuantity = Quantity.Parse(targetType, valueAsString);
146-
138+
147139
Assert.Equal(expectedQuantity, parsedQuantity);
148140
}
149141

@@ -228,7 +220,7 @@ public void Types_ReturnsKnownQuantityTypes()
228220

229221
Assert.Superset(knownQuantities.ToHashSet(), types.ToHashSet());
230222
}
231-
223+
232224
[Theory]
233225
[InlineData(1, 0, 0, 0, 0, 0, 0)]
234226
[InlineData(0, 1, 0, 0, 0, 0, 0)]

UnitsNet/CustomCode/Quantity.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static partial class Quantity
1717
/// All quantity information objects, such as <see cref="Length.Info"/> and <see cref="Mass.Info"/>, that are present in the <see cref="UnitsNetSetup.Default"/> configuration.
1818
/// </summary>
1919
public static IReadOnlyList<QuantityInfo> Infos => Quantities.Infos;
20-
20+
2121
/// <summary>
2222
/// All QuantityInfo instances mapped by quantity name that are present in the <see cref="UnitsNetSetup.Default"/> configuration.
2323
/// </summary>
@@ -35,7 +35,7 @@ public static bool TryGetUnitInfo(UnitKey unitEnum, [NotNullWhen(true)] out Unit
3535
{
3636
return Quantities.TryGetUnitInfo(unitEnum, out unitInfo);
3737
}
38-
38+
3939
/// <summary>
4040
/// Dynamically constructs a quantity from a numeric value and a unit enum value.
4141
/// </summary>
@@ -66,25 +66,6 @@ public static IQuantity From(double value, string quantityName, string unitName)
6666
return Quantities.GetUnitByName(quantityName, unitName).From(value);
6767
}
6868

69-
/// <summary>
70-
/// Dynamically constructs a quantity of the given <see cref="QuantityInfo" /> with the value in the quantity's base
71-
/// units.
72-
/// </summary>
73-
/// <param name="quantityInfo">The <see cref="QuantityInfo" /> of the quantity to create.</param>
74-
/// <param name="value">The value to construct the quantity with.</param>
75-
/// <returns>The created quantity.</returns>
76-
/// <remarks>
77-
/// This is the equivalent to:
78-
/// <code>quantityInfo.From(value, quantityInfo.BaseUnitInfo.Value)</code>
79-
/// or
80-
/// <code>quantityInfo.BaseUnitInfo.From(value)</code>
81-
/// </remarks>
82-
[Obsolete("Consider using: quantityInfo.BaseUnitInfo.From(value)")]
83-
public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value)
84-
{
85-
return quantityInfo.BaseUnitInfo.From(value);
86-
}
87-
8869
/// <summary>
8970
/// Dynamically construct a quantity from a numeric value and a unit abbreviation using <see cref="CultureInfo.CurrentCulture"/>.
9071
/// </summary>

0 commit comments

Comments
 (0)