Skip to content

zy850580380/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 (data model) by means of (design-time) T4 text template. 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.

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:
  3. edit _definitions.txt to specify units of measurement that you need for your solution.
  4. (optional) modify ProcessUnit and/or ProcessScale method(s) in _generator.tt to customize template text for generating units and/or scales.
  5. right-click on _generator.tt, select "Run Custom Tool" command (press OK on Security Warning).
  6. (optional) create extension (.cs) files to extend generated unit/scale (partial) structs with additional properties, methods or operators,
  7. Go to RuntimeLoader folder (not available in release 1.0):
  8. (optional) modify ProcessUnit and/or ProcessScale method(s) in Generator.tt to customize template text for generating run-time (late) units and/or scales.
  9. right-click on Generator.tt, select "Run Custom Tool" command (press OK on Security Warning).
  10. Compile the project.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.8%
  • Other 1.2%