@@ -46,7 +46,7 @@ public static bool TryGetUnitInfo(Enum unitEnum, [NotNullWhen(true)] out UnitInf
46
46
/// <param name="unit">Unit enum value.</param>
47
47
/// <returns>An <see cref="IQuantity"/> object.</returns>
48
48
/// <exception cref="UnitNotFoundException">Unit value is not a known unit enum type.</exception>
49
- public static IQuantity From ( QuantityValue value , Enum unit )
49
+ public static IQuantity From ( double value , Enum unit )
50
50
{
51
51
return TryFrom ( value , unit , out IQuantity ? quantity )
52
52
? quantity
@@ -61,7 +61,7 @@ public static IQuantity From(QuantityValue value, Enum unit)
61
61
/// <param name="unitName">The invariant unit enum name, such as "Meter". Does not support localization.</param>
62
62
/// <returns>An <see cref="IQuantity"/> object.</returns>
63
63
/// <exception cref="ArgumentException">Unit value is not a known unit enum type.</exception>
64
- public static IQuantity From ( QuantityValue value , string quantityName , string unitName )
64
+ public static IQuantity From ( double value , string quantityName , string unitName )
65
65
{
66
66
// Get enum value for this unit, f.ex. LengthUnit.Meter for unit name "Meter".
67
67
return UnitConverter . TryParseUnit ( quantityName , unitName , out Enum ? unitValue ) &&
@@ -78,14 +78,14 @@ public static IQuantity From(QuantityValue value, string quantityName, string un
78
78
/// Unit abbreviation matching is case-insensitive.<br/>
79
79
/// <br/>
80
80
/// This will fail if more than one unit across all quantities share the same unit abbreviation.<br/>
81
- /// Prefer <see cref="From(UnitsNet.QuantityValue ,System.Enum)"/> or <see cref="From(UnitsNet.QuantityValue ,string,string)"/> instead.
81
+ /// Prefer <see cref="From(double ,System.Enum)"/> or <see cref="From(double ,string,string)"/> instead.
82
82
/// </remarks>
83
83
/// <param name="value">Numeric value.</param>
84
84
/// <param name="unitAbbreviation">Unit abbreviation, such as "kg" for <see cref="MassUnit.Kilogram"/>.</param>
85
85
/// <returns>An <see cref="IQuantity"/> object.</returns>
86
86
/// <exception cref="UnitNotFoundException">Unit abbreviation is not known.</exception>
87
87
/// <exception cref="AmbiguousUnitParseException">Multiple units found matching the given unit abbreviation.</exception>
88
- public static IQuantity FromUnitAbbreviation ( QuantityValue value , string unitAbbreviation ) => FromUnitAbbreviation ( null , value , unitAbbreviation ) ;
88
+ public static IQuantity FromUnitAbbreviation ( double value , string unitAbbreviation ) => FromUnitAbbreviation ( null , value , unitAbbreviation ) ;
89
89
90
90
/// <summary>
91
91
/// Dynamically construct a quantity from a numeric value and a unit abbreviation.
@@ -95,15 +95,15 @@ public static IQuantity From(QuantityValue value, string quantityName, string un
95
95
/// Unit abbreviation matching is case-insensitive.<br/>
96
96
/// <br/>
97
97
/// This will fail if more than one unit across all quantities share the same unit abbreviation.<br/>
98
- /// Prefer <see cref="From(UnitsNet.QuantityValue ,System.Enum)"/> or <see cref="From(UnitsNet.QuantityValue ,string,string)"/> instead.
98
+ /// Prefer <see cref="From(double ,System.Enum)"/> or <see cref="From(double ,string,string)"/> instead.
99
99
/// </remarks>
100
100
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="CultureInfo.CurrentCulture" /> if null.</param>
101
101
/// <param name="value">Numeric value.</param>
102
102
/// <param name="unitAbbreviation">Unit abbreviation, such as "kg" for <see cref="MassUnit.Kilogram"/>.</param>
103
103
/// <returns>An <see cref="IQuantity"/> object.</returns>
104
104
/// <exception cref="UnitNotFoundException">Unit abbreviation is not known.</exception>
105
105
/// <exception cref="AmbiguousUnitParseException">Multiple units found matching the given unit abbreviation.</exception>
106
- public static IQuantity FromUnitAbbreviation ( IFormatProvider ? formatProvider , QuantityValue value , string unitAbbreviation )
106
+ public static IQuantity FromUnitAbbreviation ( IFormatProvider ? formatProvider , double value , string unitAbbreviation )
107
107
{
108
108
// TODO Optimize this with UnitValueAbbreviationLookup via UnitAbbreviationsCache.TryGetUnitValueAbbreviationLookup.
109
109
List < Enum > units = GetUnitsForAbbreviation ( formatProvider , unitAbbreviation ) ;
@@ -121,16 +121,6 @@ public static IQuantity FromUnitAbbreviation(IFormatProvider? formatProvider, Qu
121
121
return From ( value , unit ) ;
122
122
}
123
123
124
- /// <inheritdoc cref="TryFrom(QuantityValue,System.Enum,out UnitsNet.IQuantity)"/>
125
- public static bool TryFrom ( double value , Enum unit , [ NotNullWhen ( true ) ] out IQuantity ? quantity )
126
- {
127
- quantity = default ;
128
-
129
- // Implicit cast to QuantityValue would prevent TryFrom from being called,
130
- // so we need to explicitly check this here for double arguments.
131
- return TryFrom ( ( QuantityValue ) value , unit , out quantity ) ;
132
- }
133
-
134
124
/// <summary>
135
125
/// Try to dynamically construct a quantity from a value, the quantity name and the unit name.
136
126
/// </summary>
@@ -155,14 +145,14 @@ public static bool TryFrom(double value, string quantityName, string unitName, [
155
145
/// Unit abbreviation matching is case-insensitive.<br/>
156
146
/// <br/>
157
147
/// This will fail if more than one unit across all quantities share the same unit abbreviation.<br/>
158
- /// Prefer <see cref="From(UnitsNet.QuantityValue ,System.Enum)"/> or <see cref="From(UnitsNet.QuantityValue ,string,string)"/> instead.
148
+ /// Prefer <see cref="From(double ,System.Enum)"/> or <see cref="From(double ,string,string)"/> instead.
159
149
/// </remarks>
160
150
/// <param name="value">Numeric value.</param>
161
151
/// <param name="unitAbbreviation">Unit abbreviation, such as "kg" for <see cref="MassUnit.Kilogram"/>.</param>
162
152
/// <param name="quantity">The quantity if successful, otherwise null.</param>
163
153
/// <returns>True if successful.</returns>
164
154
/// <exception cref="ArgumentException">Unit value is not a known unit enum type.</exception>
165
- public static bool TryFromUnitAbbreviation ( QuantityValue value , string unitAbbreviation , [ NotNullWhen ( true ) ] out IQuantity ? quantity ) =>
155
+ public static bool TryFromUnitAbbreviation ( double value , string unitAbbreviation , [ NotNullWhen ( true ) ] out IQuantity ? quantity ) =>
166
156
TryFromUnitAbbreviation ( null , value , unitAbbreviation , out quantity ) ;
167
157
168
158
/// <summary>
@@ -173,15 +163,15 @@ public static bool TryFromUnitAbbreviation(QuantityValue value, string unitAbbre
173
163
/// Unit abbreviation matching is case-insensitive.<br/>
174
164
/// <br/>
175
165
/// This will fail if more than one unit across all quantities share the same unit abbreviation.<br/>
176
- /// Prefer <see cref="From(UnitsNet.QuantityValue ,System.Enum)"/> or <see cref="From(UnitsNet.QuantityValue ,string,string)"/> instead.
166
+ /// Prefer <see cref="From(double ,System.Enum)"/> or <see cref="From(double ,string,string)"/> instead.
177
167
/// </remarks>
178
168
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="CultureInfo.CurrentCulture" /> if null.</param>
179
169
/// <param name="value">Numeric value.</param>
180
170
/// <param name="unitAbbreviation">Unit abbreviation, such as "kg" for <see cref="MassUnit.Kilogram"/>.</param>
181
171
/// <param name="quantity">The quantity if successful, otherwise null.</param>
182
172
/// <returns>True if successful.</returns>
183
173
/// <exception cref="ArgumentException">Unit value is not a known unit enum type.</exception>
184
- public static bool TryFromUnitAbbreviation ( IFormatProvider ? formatProvider , QuantityValue value , string unitAbbreviation , [ NotNullWhen ( true ) ] out IQuantity ? quantity )
174
+ public static bool TryFromUnitAbbreviation ( IFormatProvider ? formatProvider , double value , string unitAbbreviation , [ NotNullWhen ( true ) ] out IQuantity ? quantity )
185
175
{
186
176
// TODO Optimize this with UnitValueAbbreviationLookup via UnitAbbreviationsCache.TryGetUnitValueAbbreviationLookup.
187
177
List < Enum > units = GetUnitsForAbbreviation ( formatProvider , unitAbbreviation ) ;
0 commit comments