Skip to content

Visual Studio project template for creating Units of Measurement C# class libraries for .NET Framework

License

Notifications You must be signed in to change notification settings

mangh/unitsofmeasurement

Repository files navigation

Product description

  • Visual Studio project template for creating Units of Measurement C# class library.
  • Units of measurement are generated from simple definitions in a text file according to T4 text templates. See here for an overview of unit generation process.
  • Units of measurement are generated as types (partial structs). Thus dimensional analysis can be performed as a syntax check at compile time. Dimensional issues are displayed in Visual Studio as syntax errors. See this example.
  • All fundamental dimensions are supported i.e.: Length, Time, Mass, Temperature, ElectricCurrent, AmountOfSubstance, LuminousIntensity as well as Other (e.g. Money for currency units) and any of their combinations.
  • Arithmetic (+, ++, -, --, *, /) and comparison (==, !=, <, <=, >, >=) operators to perform calculations directly on quantities of unit type. See this example.
  • Conversions of quantities to/from other (but compatible) unit types.

Go to Wiki pages for more information.


👉 There is a dotnet release for .NET Core / Standard available in the Metrology repository! 👈


How to use it?

Assuming you have already installed UnitsOfMeasurement.VSIX component (see Releases page for download and installation instructions), follow this general process to create a library:

  1. Create a new project of type "Units of Measurement C# Class Library".
  2. Go to Units folder in Solution Explorer:
    • edit _definitions.txt to specify units of measurement that you need for your solution.
    • (optional) modify _unit.t4 and/or _scale.t4 files to customize templates for generating units and/or scales.
    • right-click on _generator.tt, select "Run Custom Tool" command (press OK on Security Warning).
    • (optional) create extension (.cs) files to extend generated unit/scale (partial) structs with additional properties, methods or operators,
  3. Go to RuntimeLoader folder (not available in release 1.0):
    • right-click on Generator.tt, select "Run Custom Tool" command (press OK on Security Warning).
  4. Compile the project.

About

Visual Studio project template for creating Units of Measurement C# class libraries for .NET Framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages