Skip to content

Generic Parameters For Measurement Quantities #666

Open
@ZacharyPatten

Description

@ZacharyPatten

Generic Types

Right now, UnitsNet can only support "double" types. If you use generic types on the quantities you can allow for support of other types than just double.

I have working prototypes for Length, Mass, and Angle measurement types using generic paramters here:
https://github.com/ZacharyPatten/Towel

I wanted to share my patterns with UnitsNet, because they could help improve UnitsNet should they be adopted. However, there are pros/cons to my pattern, and it would be a massive overhaul of UnitsNet to incorporate generics, so it might not be feasible for the project to adopt the patterns.

Performance Optimization

The conversions in UnitsNet require a double conversion to/from a base unit. In that Towel project, I am using multiplication tables (in the form of jagged arrays) to cache the conversions between units. The index of the multiplication tables are provided by the values on the unit enums. This allows Towel to perform unit conversions with a single operation rather than double as UnitsNet is currently doing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpinnedIssues that should not be auto-closed due to inactivity.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions