MadsKirkFoged / EngineeringUnits

Working with units made easy with automatic unit-check and converting between units
MIT License
41 stars 10 forks source link

Request for Tips on Handling Measurements and Units Listing, and Transforming Between Strings and Objects without Reflection #63

Open CPMOliveira opened 1 week ago

CPMOliveira commented 1 week ago

Hello,

I’ve recently started using the EngineeringUnits library and have been impressed with its capabilities. However, I’m facing a couple of challenges and would appreciate some guidance:

  1. Listing Available Measurements and Units: Is there a recommended approach or built-in method for easily listing all the available measurements and their corresponding units? I would like to create a comprehensive list for a user interface, but I’m not sure of the most efficient way to achieve this.
  2. Transforming Between Strings and Objects Without Using Reflection: I need to transform strings (representing measurement names or unit symbols) into the corresponding objects in EngineeringUnits, but I’d like to avoid using reflection for performance reasons. Do you have any suggestions or best practices for achieving this transformation efficiently?

Any advice or examples would be highly appreciated.

MadsKirkFoged commented 1 week ago

Hi CPMOliveira,

1) We have a list on the frontpage: https://github.com/MadsKirkFoged/EngineeringUnits?tab=readme-ov-file#what-units-are-included

This list is generated using this code: https://github.com/MadsKirkFoged/EngineeringUnits/blob/master/CodeGen/Code/UnitListGenerator.cs

2) The closest we have right now is this:

//Got from database (Stored in two different cells)
double? value = 10;
string unit = "Meter";

//Put it back together
Length temp = value.AddUnit<LengthUnit>(unit); 

However we dont (yet) have a way to turn fx "10 m/s" in a Speed-object.

If you could come with some examples/User stories of the behavior you want, it might not be that difficult to create