Skip to content

refactor: Remove obsolete FromQuantityInfo method #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions UnitsNet.Tests/QuantityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void TryFrom_GivenNullUnit_ReturnsFalse()
Enum? nullUnit = null;
Assert.False(Quantity.TryFrom(1, nullUnit, out IQuantity? _));
}

[Fact]
public void TryFrom_GivenUnknownUnitType_ReturnsFalse()
{
Expand All @@ -53,14 +53,6 @@ public void From_GivenValueAndUnit_ReturnsQuantity()
Assert.Equal(Pressure.FromMegabars(3), Quantity.From(3, PressureUnit.Megabar));
}

[Fact]
public void FromQuantityInfo_ReturnsQuantityWithBaseUnit()
{
IQuantity quantity = Quantity.FromQuantityInfo(Length.Info, 1);
Assert.Equal(1, quantity.Value);
Assert.Equal(Length.BaseUnit, quantity.Unit);
}

[Fact]
public void ByName_GivenLength_ReturnsQuantityInfoForLength()
{
Expand Down Expand Up @@ -143,7 +135,7 @@ public void Parse_WithDefaultCulture_ReturnsQuantity(double value, string format
Type targetType = expectedQuantity.QuantityInfo.QuantityType;

IQuantity parsedQuantity = Quantity.Parse(targetType, valueAsString);

Assert.Equal(expectedQuantity, parsedQuantity);
}

Expand Down Expand Up @@ -228,7 +220,7 @@ public void Types_ReturnsKnownQuantityTypes()

Assert.Superset(knownQuantities.ToHashSet(), types.ToHashSet());
}

[Theory]
[InlineData(1, 0, 0, 0, 0, 0, 0)]
[InlineData(0, 1, 0, 0, 0, 0, 0)]
Expand Down
23 changes: 2 additions & 21 deletions UnitsNet/CustomCode/Quantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static partial class Quantity
/// 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.
/// </summary>
public static IReadOnlyList<QuantityInfo> Infos => Quantities.Infos;

/// <summary>
/// All QuantityInfo instances mapped by quantity name that are present in the <see cref="UnitsNetSetup.Default"/> configuration.
/// </summary>
Expand All @@ -35,7 +35,7 @@ public static bool TryGetUnitInfo(UnitKey unitEnum, [NotNullWhen(true)] out Unit
{
return Quantities.TryGetUnitInfo(unitEnum, out unitInfo);
}

/// <summary>
/// Dynamically constructs a quantity from a numeric value and a unit enum value.
/// </summary>
Expand Down Expand Up @@ -66,25 +66,6 @@ public static IQuantity From(double value, string quantityName, string unitName)
return Quantities.GetUnitByName(quantityName, unitName).From(value);
}

/// <summary>
/// Dynamically constructs a quantity of the given <see cref="QuantityInfo" /> with the value in the quantity's base
/// units.
/// </summary>
/// <param name="quantityInfo">The <see cref="QuantityInfo" /> of the quantity to create.</param>
/// <param name="value">The value to construct the quantity with.</param>
/// <returns>The created quantity.</returns>
/// <remarks>
/// This is the equivalent to:
/// <code>quantityInfo.From(value, quantityInfo.BaseUnitInfo.Value)</code>
/// or
/// <code>quantityInfo.BaseUnitInfo.From(value)</code>
/// </remarks>
[Obsolete("Consider using: quantityInfo.BaseUnitInfo.From(value)")]
public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value)
{
return quantityInfo.BaseUnitInfo.From(value);
}

/// <summary>
/// Dynamically construct a quantity from a numeric value and a unit abbreviation using <see cref="CultureInfo.CurrentCulture"/>.
/// </summary>
Expand Down