Skip to content

Commit 632d6af

Browse files
committed
UnitParser: Minor cleanup
1 parent be26999 commit 632d6af

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

UnitsNet/CustomCode/UnitParser.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// THE SOFTWARE.
2121

2222
using System;
23-
using System.Collections.Generic;
2423
using System.Linq;
2524
using JetBrains.Annotations;
2625
using UnitsNet.InternalHelpers;
@@ -31,13 +30,13 @@ namespace UnitsNet
3130
{
3231
public sealed class UnitParser
3332
{
34-
private readonly UnitAbbreviationsCache unitAbbreviationsCache;
33+
private readonly UnitAbbreviationsCache _unitAbbreviationsCache;
3534

3635
public static UnitParser Default { get; }
3736

3837
public UnitParser(UnitAbbreviationsCache unitAbbreviationsCache)
3938
{
40-
this.unitAbbreviationsCache = unitAbbreviationsCache ?? UnitAbbreviationsCache.Default; ;
39+
_unitAbbreviationsCache = unitAbbreviationsCache ?? UnitAbbreviationsCache.Default;
4140
}
4241

4342
static UnitParser()
@@ -76,7 +75,7 @@ TUnitType Parse<TUnitType>(string unitAbbreviation, [CanBeNull] IFormatProvider
7675
/// <param name="formatProvider">The format provider to use for lookup. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
7776
/// <returns>Unit enum value, such as <see cref="MassUnit.Kilogram" />.</returns>
7877
/// <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>
8079
[PublicAPI]
8180
#if WINDOWS_UWP
8281
internal
@@ -85,7 +84,7 @@ TUnitType Parse<TUnitType>(string unitAbbreviation, [CanBeNull] IFormatProvider
8584
#endif
8685
object Parse(string unitAbbreviation, Type unitType, [CanBeNull] IFormatProvider formatProvider = null)
8786
{
88-
if(!unitAbbreviationsCache.TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var abbreviations))
87+
if(!_unitAbbreviationsCache.TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var abbreviations))
8988
throw new UnitNotFoundException($"No abbreviations defined for unit type [{unitType}] for culture [{formatProvider}].");
9089

9190
var unitIntValues = abbreviations.GetUnitsForAbbreviation(unitAbbreviation);
@@ -139,7 +138,7 @@ bool TryParse<TUnitType>(string unitAbbreviation, out TUnitType unit) where TUni
139138
#endif
140139
bool TryParse<TUnitType>(string unitAbbreviation, [CanBeNull] IFormatProvider formatProvider, out TUnitType unit) where TUnitType : Enum
141140
{
142-
unit = default(TUnitType);
141+
unit = default;
143142

144143
if(!TryParse(unitAbbreviation, typeof(TUnitType), formatProvider, out var unitObj))
145144
return false;
@@ -179,7 +178,7 @@ bool TryParse(string unitAbbreviation, Type unitType, [CanBeNull] IFormatProvide
179178
{
180179
unit = GetDefault(unitType);
181180

182-
if(!unitAbbreviationsCache.TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var abbreviations))
181+
if(!_unitAbbreviationsCache.TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var abbreviations))
183182
return false;
184183

185184
var unitIntValues = abbreviations.GetUnitsForAbbreviation(unitAbbreviation);

0 commit comments

Comments
 (0)