-
Notifications
You must be signed in to change notification settings - Fork 393
Extending with Custom Units
- Parse and get unit abbreviation strings for your custom units via UnitSystem
- Optionally copy and modify the powershell scripts and JSON definition files to generate unit classes into your project folder structure, or simply write your own classes.
The only requirement for custom units is to have an enumeration per unit class, such as the LengthUnit enum for the Length class.
TODO
For preliminary info, see Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined()
in UnitSystemTests.cs.
Generally we want to keep the core Units.NET library small, but at the same time cover units that are widely used in different fields of engineering. As a rule of thumb, if the unit is generally known to people outside the engineering or industry domain, then it should be included in the core library. Otherwise, consider creating an external unit or create a new issue for Units.NET to start a discussion.
Candidates for custom units:
- Industry specific units, such as well logging
- Obscure or not widely used units, such as Gamma Ray American Petroleum Institute Unit
In 2.0 we added support for custom units via T4 templates. In 3.0 it was modified to use powershell scripts and JSON files and to no longer use special attributes in code. This simplifies adding units by reducing the steps, it does not require Visual Studio and you can now add custom units for parsing and getting abbreviations without using the templating system.