A package for unit conversions without engineering concepts
$ dotnet add package OSDC.UnitConversion.ConversionThis nuget package hosts the C# model for converting units of a BasePhysicalQuantity.
Classes and methods are scoped within the namespace: UnitConversion.Conversion
More info on:
https://github.com/Open-Source-Drilling-Community/UnitConversion
There are four base unit systems: SI, Metric, Imperial and US.
It is mandatory to define the unit choice for every physical quantities for
each of these based unit systems. This is done by adding a line for each
of the BaseUnitSystem in the file BaseUnitSystem.cs. This line looks like that:
Choices.Add(AccelerationQuantity.Instance.ID.ToString(), AccelerationQuantity.Instance.GetUnitChoice(AccelerationQuantity.UnitChoicesEnum.MetrePerSecondSquared).ID.ToString());
This project has one file that is automaticaly generated EnumerationQuantities.cs.
This file contains partial classes for each of the physical quantities.
Each partial class definition defines an enumeration for each of the
unit choices that are defined for this physical quantity and a
lookup table that defines the association between the enumeration
and the GUID of the unit choice.
To generate the file EnumerationQuantities.cs, one must run the program
GenerateEnumerations. The generation of the file is necessary each
time a modification is made in the list of unit choices of a physical
quantity or when a new physical quantity is added or removed. However,
there is a potential bootstrap problem with the definitions of the
unit choices for the BaseUnitSystem. As each BaseUnitSystem has
a list of unit choices and these choices are usually defined using
the unit choice enumeration, if the enumeration does not yet exist
or its name is changed, then the project does not compile and it is not
possible to generate the enumerations using the program .
So it is advised to define the unit choice for the particular physical
quantity using its name or its , then generate the enumerations by running
the program and finally replace the name of the unit
choice with its equivalent enumeration.
GenerateEnumerationsGUIDGenerateEnumerationChoices.Add(AccelerationQuantity.Instance.ID.ToString(), AccelerationQuantity.Instance.GetUnitChoice("metre per second squared").ID.ToString());GenerateEnumerations
Choices.Add(AccelerationQuantity.Instance.ID.ToString(), AccelerationQuantity.Instance.GetUnitChoice(AccelerationQuantity.UnitChoicesEnum.MetrePerSecondSquared).ID.ToString());Eric Cayeux, NORCE Energy Modelling and Automation
Gilles Pelfrene, NORCE Energy Modelling and Automation