@@ -11,6 +11,38 @@ namespace UnitsNet;
1111/// </summary>
1212public static class QuantityExtensions
1313{
14+ #if ! NET
15+ /// <summary>
16+ /// Gets the <see cref="UnitInfo"/> for the unit this quantity was constructed with.
17+ /// </summary>
18+ /// <param name="quantity">The quantity.</param>
19+ /// <returns>The <see cref="UnitInfo"/> for the quantity's unit.</returns>
20+ /// <remarks>
21+ /// On .NET 5+ targets, this is available as a default interface member property
22+ /// <c>IQuantity.UnitInfo</c> instead.
23+ /// </remarks>
24+ public static UnitInfo GetUnitInfo ( this IQuantity quantity )
25+ {
26+ return quantity . QuantityInfo [ quantity . UnitKey ] ;
27+ }
28+
29+ /// <summary>
30+ /// Gets the <see cref="UnitInfo{TUnit}"/> for the unit this quantity was constructed with.
31+ /// </summary>
32+ /// <typeparam name="TUnit">The unit enum type.</typeparam>
33+ /// <param name="quantity">The quantity.</param>
34+ /// <returns>The <see cref="UnitInfo{TUnit}"/> for the quantity's unit.</returns>
35+ /// <remarks>
36+ /// On .NET 5+ targets, this is available as a default interface member property
37+ /// <c>IQuantity<TUnitType>.UnitInfo</c> instead.
38+ /// </remarks>
39+ public static UnitInfo < TUnit > GetUnitInfo < TUnit > ( this IQuantity < TUnit > quantity )
40+ where TUnit : struct , Enum
41+ {
42+ return quantity . QuantityInfo [ quantity . Unit ] ;
43+ }
44+ #endif
45+
1446 /// <inheritdoc cref="IQuantity.As(UnitKey)" />
1547 /// <remarks>This should be using UnitConverter.Default.ConvertValue(quantity, toUnit) </remarks>
1648 internal static double GetValue < TQuantity > ( this TQuantity quantity , UnitKey toUnit )
0 commit comments