Skip to content

Commit 21c2f84

Browse files
Code review response v3
1 parent 4673c9a commit 21c2f84

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

UnitsNet.Tests/UnitConverterTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public void ConvertByName_ConvertsTheValueToGivenUnit(double expectedValue, doub
3737
}
3838

3939
[Fact]
40-
public void ConvertByName__QuantityCaseInsensitive()
40+
public void ConvertByName_QuantityCaseInsensitive()
4141
{
4242
Assert.Equal(0, UnitConverter.ConvertByName(0, "length", "Meter", "Centimeter"));
4343
}
4444

4545
[Fact]
46-
public void ConvertByName__UnitTypeCaseInsensitive()
46+
public void ConvertByName_UnitTypeCaseInsensitive()
4747
{
4848
Assert.Equal(0, UnitConverter.ConvertByName(0, "Length", "meter", "Centimeter"));
4949
}

UnitsNet/CustomCode/UnitValueAbbreviationLookup.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,21 @@ internal List<string> GetAbbreviationsForUnit(int unit)
6363

6464
internal List<int> GetUnitsForAbbreviation(string abbreviation)
6565
{
66-
abbreviation = abbreviation.ToLower();
67-
if(!abbreviationToUnitMap.TryGetValue(abbreviation, out var units))
68-
abbreviationToUnitMap[abbreviation] = units = new List<int>();
66+
var lowerCaseAbbreviation = abbreviation.ToLower();
67+
if(!abbreviationToUnitMap.TryGetValue(lowerCaseAbbreviation, out var units))
68+
abbreviationToUnitMap[lowerCaseAbbreviation] = units = new List<int>();
6969

7070
return units.Distinct().ToList();
7171
}
7272

7373
internal void Add(int unit, string abbreviation, bool setAsDefault = false)
7474
{
75-
// abbreviation = abbreviation.ToLower();
76-
var lower = abbreviation.ToLower();
75+
var lowerCaseAbbreviation = abbreviation.ToLower();
7776
if(!unitToAbbreviationMap.TryGetValue(unit, out var abbreviationsForUnit))
7877
abbreviationsForUnit = unitToAbbreviationMap[unit] = new List<string>();
7978

80-
if(!abbreviationToUnitMap.TryGetValue(lower, out var unitsForAbbreviation))
81-
abbreviationToUnitMap[lower] = unitsForAbbreviation = new List<int>();
79+
if(!abbreviationToUnitMap.TryGetValue(lowerCaseAbbreviation, out var unitsForAbbreviation))
80+
abbreviationToUnitMap[lowerCaseAbbreviation] = unitsForAbbreviation = new List<int>();
8281

8382
abbreviationsForUnit.Remove(abbreviation);
8483
unitsForAbbreviation.Remove(unit);

UnitsNet/UnitConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ private static bool TryParseUnit(Type unitType, string unitName, out object unit
407407

408408
private static bool TryGetUnitType(string quantityName, out Type unitType)
409409
{
410-
quantityName += "Unit";
410+
var quantityTypeName = quantityName += "Unit"; // ex. LengthUnit
411411
unitType = UnitTypes.FirstOrDefault(x =>
412-
x.Name.Equals(quantityName, StringComparison.OrdinalIgnoreCase));
412+
x.Name.Equals(quantityTypeName, StringComparison.OrdinalIgnoreCase));
413413

414414
if(unitType == null)
415415
return false;

0 commit comments

Comments
 (0)