Skip to content

Extending with Custom Units

Andreas Gullberg Larsen edited this page Jul 15, 2015 · 20 revisions

What Does It Do?

  • 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.

Requirements

The only requirement for custom units is to have an enumeration per unit class, such as the LengthUnit enum for the Length class.

How to Use

TODO

For preliminary info, see Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined() in UnitSystemTests.cs.

Custom Units vs Core Units

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:

History

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.

Clone this wiki locally