20
20
// THE SOFTWARE.
21
21
22
22
using System ;
23
- using System . Collections . Generic ;
24
23
using System . Linq ;
25
24
using JetBrains . Annotations ;
26
25
using UnitsNet . InternalHelpers ;
@@ -31,13 +30,13 @@ namespace UnitsNet
31
30
{
32
31
public sealed class UnitParser
33
32
{
34
- private readonly UnitAbbreviationsCache unitAbbreviationsCache ;
33
+ private readonly UnitAbbreviationsCache _unitAbbreviationsCache ;
35
34
36
35
public static UnitParser Default { get ; }
37
36
38
37
public UnitParser ( UnitAbbreviationsCache unitAbbreviationsCache )
39
38
{
40
- this . unitAbbreviationsCache = unitAbbreviationsCache ?? UnitAbbreviationsCache . Default ; ;
39
+ _unitAbbreviationsCache = unitAbbreviationsCache ?? UnitAbbreviationsCache . Default ;
41
40
}
42
41
43
42
static UnitParser ( )
@@ -76,7 +75,7 @@ TUnitType Parse<TUnitType>(string unitAbbreviation, [CanBeNull] IFormatProvider
76
75
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
77
76
/// <returns>Unit enum value, such as <see cref="MassUnit.Kilogram" />.</returns>
78
77
/// <exception cref="UnitNotFoundException">No units match the abbreviation.</exception>
79
- /// <exception cref="AmbiguousUnitParseException">More than one unit matches the abbrevation .</exception>
78
+ /// <exception cref="AmbiguousUnitParseException">More than one unit matches the abbreviation .</exception>
80
79
[ PublicAPI ]
81
80
#if WINDOWS_UWP
82
81
internal
@@ -85,7 +84,7 @@ TUnitType Parse<TUnitType>(string unitAbbreviation, [CanBeNull] IFormatProvider
85
84
#endif
86
85
object Parse ( string unitAbbreviation , Type unitType , [ CanBeNull ] IFormatProvider formatProvider = null )
87
86
{
88
- if ( ! unitAbbreviationsCache . TryGetUnitValueAbbreviationLookup ( unitType , formatProvider , out var abbreviations ) )
87
+ if ( ! _unitAbbreviationsCache . TryGetUnitValueAbbreviationLookup ( unitType , formatProvider , out var abbreviations ) )
89
88
throw new UnitNotFoundException ( $ "No abbreviations defined for unit type [{ unitType } ] for culture [{ formatProvider } ].") ;
90
89
91
90
var unitIntValues = abbreviations . GetUnitsForAbbreviation ( unitAbbreviation ) ;
@@ -139,7 +138,7 @@ bool TryParse<TUnitType>(string unitAbbreviation, out TUnitType unit) where TUni
139
138
#endif
140
139
bool TryParse < TUnitType > ( string unitAbbreviation , [ CanBeNull ] IFormatProvider formatProvider , out TUnitType unit ) where TUnitType : Enum
141
140
{
142
- unit = default ( TUnitType ) ;
141
+ unit = default ;
143
142
144
143
if ( ! TryParse ( unitAbbreviation , typeof ( TUnitType ) , formatProvider , out var unitObj ) )
145
144
return false ;
@@ -179,7 +178,7 @@ bool TryParse(string unitAbbreviation, Type unitType, [CanBeNull] IFormatProvide
179
178
{
180
179
unit = GetDefault ( unitType ) ;
181
180
182
- if ( ! unitAbbreviationsCache . TryGetUnitValueAbbreviationLookup ( unitType , formatProvider , out var abbreviations ) )
181
+ if ( ! _unitAbbreviationsCache . TryGetUnitValueAbbreviationLookup ( unitType , formatProvider , out var abbreviations ) )
183
182
return false ;
184
183
185
184
var unitIntValues = abbreviations . GetUnitsForAbbreviation ( unitAbbreviation ) ;
0 commit comments