You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes #1263
This was initially made internal while we matured its design, but it has
been stable for a long time now and ready for external use. Making it
public makes it possible to parse custom units, as described in the
wiki.
### Changes
- Make `QuantityParser` and its `Parse`, `TryParse` methods public
- Add xmldoc
/// A method signature for creating a quantity given a numeric value and a strongly typed unit, for example 1.0 and <see cref="LengthUnit.Meter"/>.
17
+
/// </summary>
18
+
/// <typeparam name="TQuantity">The type of quantity to create, such as <see cref="Length"/>.</typeparam>
19
+
/// <typeparam name="TUnitType">The type of unit enum that belongs to this quantity, such as <see cref="LengthUnit"/> for <see cref="Length"/>.</typeparam>
/// Creates an instance of <see cref="QuantityParser"/>, optionally specifying an <see cref="UnitAbbreviationsCache"/>
44
+
/// with unit abbreviations to use when parsing.
45
+
/// </summary>
46
+
/// <param name="unitAbbreviationsCache">(Optional) The unit abbreviations cache, or specify <c>null</c> to use <see cref="UnitAbbreviationsCache.Default"/>.</param>
/// Parses a quantity from a string, such as "1.2 kg" to <see cref="Length"/> or "100 cm" to <see cref="Mass"/>.
60
+
/// </summary>
61
+
/// <param name="str">The string to parse, such as "1.2 kg".</param>
62
+
/// <param name="formatProvider">The culture for looking up localized unit abbreviations for a language, and for parsing the number formatted in this culture. Defaults to <see cref="CultureInfo.CurrentCulture"/>.</param>
63
+
/// <param name="fromDelegate">A function to create a quantity given a numeric value and a unit enum value.</param>
64
+
/// <typeparam name="TQuantity">The type of quantity to create, such as <see cref="Length"/>.</typeparam>
65
+
/// <typeparam name="TUnitType">The type of unit enum that belongs to this quantity, such as <see cref="LengthUnit"/> for <see cref="Length"/>.</typeparam>
66
+
/// <returns>The parsed quantity if successful.</returns>
67
+
/// <exception cref="ArgumentNullException">The string was null.</exception>
68
+
/// <exception cref="FormatException">Failed to parse quantity.</exception>
/// Tries to parse a quantity from a string, such as "1.2 kg" to <see cref="Length"/> or "100 cm" to <see cref="Mass"/>.
93
+
/// </summary>
94
+
/// <param name="str">The string to parse, such as "1.2 kg".</param>
95
+
/// <param name="formatProvider">The culture for looking up localized unit abbreviations for a language, and for parsing the number formatted in this culture. Defaults to <see cref="CultureInfo.CurrentCulture"/>.</param>
96
+
/// <param name="fromDelegate">A function to create a quantity given a numeric value and a unit enum value.</param>
97
+
/// <param name="result">The parsed quantity if successful, otherwise null.</param>
98
+
/// <typeparam name="TQuantity">The type of quantity to create, such as <see cref="Length"/>.</typeparam>
99
+
/// <typeparam name="TUnitType">The type of unit enum that belongs to this quantity, such as <see cref="LengthUnit"/> for <see cref="Length"/>.</typeparam>
100
+
/// <returns>True if successful.</returns>
101
+
/// <exception cref="ArgumentNullException">The string was null.</exception>
102
+
/// <exception cref="FormatException">Failed to parse quantity.</exception>
/// Workaround for C# not allowing to pass on 'out' param from type Length to IQuantity, even though the are compatible.
123
+
/// Tries to parse a quantity from a string, such as "1.2 kg" to <see cref="Length"/> or "100 cm" to <see cref="Mass"/>.
85
124
/// </summary>
125
+
/// <remarks>
126
+
/// Similar to <see cref="TryParse{TQuantity,TUnitType}(string?,System.IFormatProvider?,UnitsNet.QuantityFromDelegate{TQuantity,TUnitType},out TQuantity)"/>,
127
+
/// but returns <see cref="IQuantity"/> instead. This is workaround for C# not allowing to pass on 'out' param from type Length to IQuantity,
128
+
/// even though the are compatible.
129
+
/// </remarks>
130
+
/// <param name="str">The string to parse, such as "1.2 kg".</param>
131
+
/// <param name="formatProvider">The culture for looking up localized unit abbreviations for a language, and for parsing the number formatted in this culture. Defaults to <see cref="CultureInfo.CurrentCulture"/>.</param>
132
+
/// <param name="fromDelegate">A function to create a quantity given a numeric value and a unit enum value.</param>
133
+
/// <param name="result">The parsed quantity if successful, otherwise null.</param>
134
+
/// <typeparam name="TQuantity">The type of quantity to create, such as <see cref="Length"/>.</typeparam>
135
+
/// <typeparam name="TUnitType">The type of unit enum that belongs to this quantity, such as <see cref="LengthUnit"/> for <see cref="Length"/>.</typeparam>
136
+
/// <returns>True if successful.</returns>
137
+
/// <exception cref="ArgumentNullException">The string was null.</exception>
138
+
/// <exception cref="FormatException">Failed to parse quantity.</exception>
0 commit comments