UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

XP One nuget per quantity

Open angularsen opened this issue 3 years ago • 6 comments

Related to #372, #1180

Experiment with splitting up UnitsNet nuget into:

  • UnitsNet.Core (common types and abstractions)
  • UnitsNet.Length
  • UnitsNet.Mass
  • etc..

This is already done for UnitsNet.nanoFramework nugets: https://www.nuget.org/packages?q=unitsnet.nanoframework

We might also provide meta nuget packages that bring in multiple nugets in a single package:

  • UnitsNet (all nugets, like today)
  • UnitsNet.Meta.SI (all SI and SI derived nugets, such as Length, Force, Mass, Area, Speed etc)
  • UnitsNet.Meta.Main (the most widely used nugets, striving for 80/20 rule)

Benefits

  • Smaller size, only bring the quantities you need. The UnitsNet.dll is ~2MB as of 2023-01-07.
  • More extensible, it forces a design where plugging in 3rd party quantities is simpler.

Problems

  • QuantityType enum must be replaced by strings and using QuantityInfo instead
  • UnitSystem and BaseUnits rely on the 7 SI quantities Length, Mass, etc.
  • Arithmetic across quantities may not be feasible for the library to provide, such as Speed = Length / Duration and Mass.FromGravitationalForce(Force f). We might be able to provide this with meta nuget packages that bring in the most common quantities and arithmetic/conversions between them.

Design proposal

  • Use reflection to look up all quantities in loaded assemblies at startup instead of hard coding it, to allow plugging in 3rd party quantities. Need to provide some configuration for assemblies to search or quantities to load.
  • Make use of QuantityInfo to fully describe a quantity, instead of relying on generated code for known quantities spread over various types.
    • Unit abbreviations for different cultures, currently loaded by UnitAbbreviationsCache.LoadGeneratedAbbreviations() based on generated code.
    • Unit conversion functions, currently defined by generated code in Acceleration.RegisterDefaultConversions and similar for other quantities.

angularsen avatar Jan 07 '23 13:01 angularsen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 18 '23 07:06 stale[bot]

test comment

angularsen avatar Jul 16 '23 16:07 angularsen

test 2

angularsen avatar Jul 16 '23 16:07 angularsen

test 3

angularsen avatar Jul 16 '23 16:07 angularsen

test 4

angularsen avatar Jul 16 '23 17:07 angularsen

test 5

angularsen avatar Jul 16 '23 17:07 angularsen