Skip to content

QuantityValue implemented as a fractional number 🐲 #1544

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 36 commits into
base: master
Choose a base branch
from

Conversation

lipchev
Copy link
Collaborator

@lipchev lipchev commented Apr 13, 2025

  • QuantityValue implemented as a fractional number
  • IQuantity interfaces optimized (some methods refactored as extensions)
  • UnitInfo: introduced two new properties: ConversionFromBase and ConversionToBase which are used instead of the switch(Unit) conversion
  • QuantityInfoLookup is now public
  • UnitsNetSetup: introduced helper methods for adding external quantities, or re-configuring one or more of the existing ones
  • UntAbbreviationsCache: introduced additional factory methods (using a configuration delegate)
  • UnitParser: introduced additional factory methods (using a configuration delegate)
  • UnitConverter: re-implemented (multiple versions)
  • Inverse relationship mapping implemented as a type of implicit conversion
  • updated the JsonNet converters
  • introducing the SystemTextJson project
  • added a new UnitsNetConfiguration project to the Samples, showcasing the new configuration options
  • many more tests and benchmarks (perhaps too many)

- IQuantity interfaces optimized (some methods refactored as extensions)
- QuantityInfo/UnitInfo hierachy re-implemented (same properties, different constructors)
- QuantityInfoLookup is now public
- UntAbbreviationsCache, UnitParser, QuantityParser optimized
- UnitConverter: re-implemented (multiple versions)
- removed the IConvertible interface
- updated the JsonNet converters
- introducing the SystemTextJson project
- added a new UnitsNetConfiguration to the Samples project showcasing the new configuration options
- many more tests and benchmarks (perhaps too many)
@lipchev
Copy link
Collaborator Author

lipchev commented Apr 13, 2025

@angularsen Clearly, I don't expect this to get merged in the Gitty up! fashion, but at least we have the whole picture, with sources that I can reference.

If you want, send me an e-mail, we could do a quick walk-through / discussion.

lipchev added 2 commits April 18, 2025 00:27
…lection constructors with IEnumerable

- `UnitAbbreviationsCacheInitializationBenchmarks`: replaced some obsolete usages
@angularsen
Copy link
Owner

100k lines removed, 100k lines added 🙈

image

@lipchev
Copy link
Collaborator Author

lipchev commented Apr 18, 2025

100k lines removed, 100k lines added 🙈

I tried to create this PR twice before (many months ago), while the changes to the unit definitions were still not merged- and the web interface was giving me an error when trying to browse the files changed.. Something like "Too many files to display" 😄

@angularsen
Copy link
Owner

Ok, I'm not going to get through a review of this many files anytime soon.
Maybe we should have a screen sharing session and go through it together. I may have some time this weekend, what about you? What timezone are you in?

On the surface though, it seems like this could be split up into chunks. I know it's tedious and extra work, but it will be way faster to review. Do you see any chunks of changes to easily split off into separate PRs?

@lipchev
Copy link
Collaborator Author

lipchev commented Apr 18, 2025

Ok, I'm not going to get through a review of this many files anytime soon. Maybe we should have a screen sharing session and go through it together. I may have some time this weekend, what about you? What timezone are you in?

Sofia (GMT+3), but time zones are not relevant to my sleep schedule - so basically any time you want.

On the surface though, it seems like this could be split up into chunks. I know it's tedious and extra work, but it will be way faster to review. Do you see any chunks of changes to easily split off into separate PRs?

Yes, I do have some ideas:

  1. UnitAbbreviationsCache and the UnitParser should be more or less free of changes once UnitAbbreviationsCache.CreateEmpty should use the default QuantityInfoLookup #1548 is merged
  2. I plan to remove the IConvertible interface tonight (lots of red points there)
  3. The QuantityParser has just a few minor changes which I was going to try to push as well (other than that it's mostly just double changing to QuantityValue)
  4. QuantityFormatter - there was an issue that I created earlier that should (mostly) solve the differences
  5. Refactoring the QuantityInfo can theoretically be done without the ConversionExpressions (which would open the way for the changes to the IQuantity interface and some of the extension methods).
  6. UnitParser: introduce two new method: GetUnitFromAbbreviation and TryGetUnitFromAbbreviation returning a UnitInfo (which could be used for constructing an instance of the quantity)
  7. Introduce the changes to the IQuantity interface and some of the extension methods
  8. Move the exceptions in their own folder and replace the usages of the NotImplementedException with the appropriate UnitNotFoundException
  9. Update the UnitTestBaseClassGenerator - I've refactored the Parse/TryParse tests (completing the test coverage) - having a look at the diff on the MassTestsBase.g.cs, it looks like these account for about half of all diffs in the PR 😄
  10. Make the QuantityInfoLookup public: apart from the extra constructors, there doesn't appear to be any other differences- and I don't see any reason to keep it internal
  11. The JsonQuantityConverter stuff from SystemText could theoretically come with it's double versions first (but we do need to have a discussion about it)

Hopefully by the time we get to 5) you'd be up to speed (and fed up with PRs) and we can turn back to reviewing / working on the rest of it as a whole 😄

@angularsen
Copy link
Owner

Ok, sounds good. Just send PRs my way and I'll try to get to them. I have a little bit of extra time this weekend.

Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

Copy link

This PR was automatically closed due to inactivity.

@github-actions github-actions bot closed this Jun 28, 2025
@lipchev lipchev reopened this Jul 25, 2025
@lipchev
Copy link
Collaborator Author

lipchev commented Jul 25, 2025

@angularsen I've synced the changes with the main branch, updated the header-comment and the task-list.
Having a look at the changes, things don't look so scary anymore... I did notice a few bits of commented-code which I'll clean up tomorrow, and then move down the task-list.

@angularsen
Copy link
Owner

Great! I may have some time this weekend to look at it.

@lipchev
Copy link
Collaborator Author

lipchev commented Jul 26, 2025

@angularsen By removing the EnumUtils in 7264a1f you broke my .net48 tests. In master we aren't testing net framework in the main tests project, but given how many #if NET checks we have, I thought it would make sense to include it here (despite how terribly slow those tests are, compared to .net 8+).
So how do you wanna handle this? I could keep the EnumUtils and add an #if NET optimization in its body?

@angularsen
Copy link
Owner

With #1543 there should be a new EnumHelper marked internal, can you reuse that?
Otherwise, for tests just add whatever you need, no big deal.

@lipchev
Copy link
Collaborator Author

lipchev commented Jul 30, 2025

@angularsen FYI - I'm keeping the nugget version in this PR one step ahead of the official pre-release version so that the nugget references in the Samples projects pick up the right one (same goes for my nugget sources).

PS Before running the Samples, make sure you have built the Artifacts (from the global build script).

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

Successfully merging this pull request may close these issues.

2 participants