Skip to content

✨Configure unit conversions via IQuantityInfo #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

angularsen
Copy link
Owner

  • Add IQuantityInfo.RegisterUnitConversions callback to configure unit conversions
  • Change UnitConverter to configure unit conversions from a list of IQuantityInfo
  • Change UnitsNetSetup to pass the default quantity infos into its default UnitConverter
  • Add sample conversions for HowMuch

- Add `IQuantityInfo.RegisterUnitConversions` callback to configure unit conversions
- Change `UnitConverter` to configure unit conversions from a list of `IQuantityInfo`
- Change `UnitsNetSetup` to pass the default quantity infos into its default `UnitConverter`
- Add sample conversions for `HowMuch`
@angularsen angularsen requested a review from lipchev July 25, 2025 22:03
@angularsen
Copy link
Owner Author

Maybe you already have done something like this in your dragon PR, but while reviewing it seemed natural to add something like this.

{
var registerMethod = quantity.QuantityType.GetMethod(nameof(Length.RegisterDefaultConversions), BindingFlags.NonPublic | BindingFlags.Static);
registerMethod?.Invoke(null, new object[]{unitConverter});
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good riddance to this reflection stuff

@lipchev
Copy link
Collaborator

lipchev commented Jul 25, 2025

Yes, these are already covered by introducing the ConversionFromBase and ConversionToBase properties (of type ConversionExpression) in the UnitInfo.

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93%. Comparing base (d21e526) to head (f7cc6d3).

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1578   +/-   ##
======================================
  Coverage      93%     93%           
======================================
  Files         311     311           
  Lines       28781   28780    -1     
======================================
  Hits        26864   26864           
+ Misses       1917    1916    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants