CodePlexProject Hosting for Open Source Software

Measure<T> represents a value type associated to an unit. Its gives support for scale and arithmetic operations by considering operand units. The following class diagram describes the model of Measure<T>:

- A Measure<T> (13 cm3/€) is represented by a Value (13) and an Unit (cm3/€).
- The ScaleTo method scales a measure to a specified UnitPrefix by considering its root unit.

*13 cm3/€ ScaleTo(UnitPrefixes.Deci) => 0,013 dm3/€* - The ScaleInnerUnitTo methods scales a measure to a specified UnitPrefix by considering the specified InnerUnit.

*13 cm3/€ ScaleInnerUnitTo(€, UnitPrefixes.Kilo) => 13000 cm3/k€* - Operations on Measure<T>.Value are implemented via lambda expressions thanks to Jon Skeet and Marc Gravell
- Arithmetic operators scale internally operands according to the lowest unit when possible.

*3 €/g + 2 €/kg = 3,002 €/g*

*3 €/g – 2 €/kg = 2,998 €/g* - Addition and Substraction operators raise exceptions when scaled operands have different unit.

*3 €/g – 4 €/m = ? => exception* - Multiplication and Divison operators raise exceptions when result represents a measure with a composite unit.

*3 € * 2 m = 5 €m => exception* - Multiplication and Divison operators consider the operand inner units when invoked.

*100 €/m * 3 km = 300000 €*

100 €/km2 / 3 m = 0.00003 €/m3

- The ScaleTo method scales a measure to a specified UnitPrefix by considering its root unit.
- An Unit is represented by an UnitPrefix (c), a Name (m), an Exponent (3) and an optional recursive InnerUnit (€).
- An unit is case sensitive.
- Units with name duplicates are not authorized.

*13 cm3/m is not authorized.* - The following regular expression represents the UnitPattern used for explicit conversions from string to Unit:

*(?-i)(?<Prefix>\bda|\b[y,z,a,f,p,n,µ,m,c,d,h,k,M,G,T,P,E,Z,Y]{1})(?<Unit>[\p{S}\p{P}a-zA-Z]*)(?<Exponent>[0-9]*)*

- An UnitPrefix is represented by a Symbol (c) and an Exponent (2 for E-2).
- UnitPrefixes provide available prefixes compliant to the International System of Units.

Last edited Jan 9, 2012 at 8:54 PM by odanvin, version 6