UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

`QuantityInfo`: internalizing the `UnitInfo` construction

Open lipchev opened this issue 8 months ago • 2 comments

  • QuantityInfo: internalizing the UnitInfo construction
  • QuantityInfo: introducing a delegate for constructing the quantity (required only for net standard)
  • QuantityInfo: introducing an optional ResourceDictionary
  • QuantityInfo: replacing the TUnit[] with an IReadOnlyCollection<TUnit>
  • UnitInfo: introducing a back-reference to the QuantityInfo (making the QuantityName [Obsolete])
  • IQuantity: added the QuantityInfo<TQuantity, TUnit>, the From(double, TUnit) method and default implementations for the non-generic properties
  • QuantityInfoLookup: added another collection for the quantity by type mapping (replacing the generated code in Quantity.g.s).
  • UnitAbbreviationsCache: ReadAbbreviationsFromResourceFile implemented using the provided ResourceManager (if available)
  • updating the QuantityInfo definitions for all quantities (introducing a concrete class, such as MassInfo) with helpers for creating a derived configuration
  • HowMuch upgraded to IQuantity<HowMuch, HowMuchUnit> (the original QuantityInfo is now abstract)
  • Quantity refactored the Parse / From* methods using the default QuantityParser / QuantityInfoLookup
  • Quantity replaced the ByName dictionary with an IReadOnlyDictionary
  • UnitsNet.csproj / UnitsNet.Tests.csproj: added some (specific) implicit usings

lipchev avatar Apr 21 '25 05:04 lipchev

@angularsen The most breaking thing here should be the change from MassUnit[] to IReadOnlyCollection<MassUnit>: we still have the IReadOnlyList<UnitInfo>, so if anybody want to do a for-loop that's still an option, but in my opinion, having the indexer (backed by a dictionary) is more interesting than having 2 read-only lists, but if you want I could switch it.

Providing a delegate and resource dictionary in the QuantityInfo does look like we're mixing the domain with the infrastructure, but since we want to support nestandard2.0 this was the simplest way to have an all in one definition, that can support both internal and external quantities.

PS The UnitInfo is still missing the conversion expressions, that should be used by the UnitConverter, and we still don't have a way to configure/customize the UnitsNetSetup.Default, but for the rest of the classes (UnitParser, UnitAbbreviationsCache etc)- we're pretty close to my final version.

PS2 The new size is:

2.53 MB (2 661 376 bytes)

which is up from

2.18 MB (2 287 616 bytes)

but that would go down again, when I remove all the RegisterDefaultConversions and the switch expressions:

1.78 MB (1 867 776 bytes)

lipchev avatar Apr 21 '25 15:04 lipchev

@lipchev just a heads up that this week is crazy for me and I'm traveling this weekend, not sure I'll get around to much

angularsen avatar Apr 24 '25 19:04 angularsen

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.

github-actions[bot] avatar Jun 24 '25 02:06 github-actions[bot]

This PR was automatically closed due to inactivity.

github-actions[bot] avatar Jul 01 '25 02:07 github-actions[bot]