Add name-based unit abbreviation lookup overloads#1695
Conversation
ReviewSmall, focused addition — new name-based overloads on Breaking changes: None. Purely additive public API (two new overloads with an optional trailing parameter), no changes to generated code or existing signatures. New quantities/units: N/A — no changes to Generated code: N/A — only hand-written code in Code quality / conventions:
Potential bugs: None spotted. The null checks happen before the lookup, and case-insensitivity is delegated to Test coverage: Good — covers success, case-insensitivity, restricted-quantity-set behavior, invalid quantity/unit names, and null argument names for both new overloads. Performance/security: No concerns — this is a thin convenience wrapper around existing lookup logic. Nice, minimal PR overall. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1695 +/- ##
=======================================
Coverage 96% 96%
=======================================
Files 457 455 -2
Lines 30163 29558 -605
=======================================
- Hits 29098 28519 -579
+ Misses 1065 1039 -26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Motivation
#1067asks for looking up unit abbreviations by quantity and unit names instead of requiring unit enum values. The parser side andUnitInfooverloads already exist, but the directUnitAbbreviationsCache.Default.GetDefaultAbbreviation("Length", "Millimeter")shape was still missing.Closes #1067.
Changes
UnitAbbreviationsCache.GetDefaultAbbreviation(string quantityName, string unitName, IFormatProvider? formatProvider = null).UnitAbbreviationsCache.GetUnitAbbreviations(string quantityName, string unitName, IFormatProvider? formatProvider = null)for the same lookup shape.Validation
dotnet test UnitsNet.Tests --filter "FullyQualifiedName~UnitAbbreviationsCacheTests"dotnet test UnitsNet.Tests --no-build --filter "FullyQualifiedName~UnitAbbreviationsCacheTests"