Units of measurement manager.
More...
Units of measurement manager.
Singleton instance and main access point for quantities, units and unit conversions.
This class is thread-safe.
- Author
- Petroware AS
Add the specified quantity to this unit manager.
- Parameters
-
- Exceptions
-
ArgumentNullException | If quantity is null. |
ArgumentException | If quantity is already contained in this manager. |
void AddUnitAlias |
( |
string |
unitSymbolAlias, |
|
|
string |
unitSymbol |
|
) |
| |
Add specified alias to be associated with the given official unit symbol.
The alias will be used when identifying Unit instances from unit symbols and affects all methods of this class taking unit symbol as argument.
Multiple aliases can be added for each unit symbol.
- Parameters
-
unitSymbolAlias | Alias to add. Non-null. |
unitSymbol | Unit symbol to associated alias with. Non-null. |
- Exceptions
-
ArgumentNullException | If unitSymbolAlias or unitSymbol is null. |
bool CanConvert |
( |
Unit |
unit1, |
|
|
Unit |
unit2 |
|
) |
| |
Check if it is possible to convert between the two specified units.
- Parameters
-
unit1 | First unit to consider. Non-null. |
unit2 | Second unit to consider. Non-null. |
- Returns
- True if it is possible to convert between the two, false otherwise.
- Exceptions
-
ArgumentNullException | If unit1 or unit2 is null. |
bool CanConvert |
( |
string |
unitSymbol1, |
|
|
string |
unitSymbol2 |
|
) |
| |
Check if it is possible to convert between the two specified units.
- Parameters
-
unitSymbol1 | Unit symbol of first unit to consider. Null if unitless. |
unitSymbol2 | Unit symbol of second unit to consider. Null if unitless. |
- Returns
- True if it is possible to convert between the two, false otherwise.
static double Convert |
( |
Unit |
fromUnit, |
|
|
Unit |
toUnit, |
|
|
double |
value |
|
) |
| |
|
static |
Convert the specified value between the two given units.
Note that it is the client responsibility to check if it makes sense to convert between the given units. This method simply converts the value to base of the from unit, and convert this result from base of the to unit, without considering the compatibility between the two.
- Parameters
-
fromUnit | Current unit of value. Non-null. |
toUnit | Unit to convert to. Non-null. |
value | Value to convert. |
- Returns
- Converted value.
- Exceptions
-
ArgumentNullException | If fromUnit or toUnit is null. |
double Convert |
( |
string |
fromUnitSymbol, |
|
|
string |
toUnitSymbol, |
|
|
double |
value |
|
) |
| |
Convert the specified value between the two given units.
Note that it is the client responsibility to check if it makes sense to convert between the given units. This method simply converts the value to base of the from unit, and convert this result from base of the to unit, without considering the compatibility between the two.
- Parameters
-
fromUnitSymbol | Unit symbol of current unit of value. Non-null. |
toUnitSymbol | Unit symbol of unit to convert to. Non-null. |
value | Value to convert. |
- Returns
- Converted value, or the input value it unit symbols are unknown.
- Exceptions
-
ArgumentNullException | If fromUnitSymbol or toUnitSymbol is null. |
IList<Unit> FindConvertibleUnits |
( |
Unit |
unit | ) |
|
Return all units that are convertible with the specified unit.
- Parameters
-
unit | Unit to consider. Non-null. |
- Returns
- All convertible units. Never null.
- Exceptions
-
ArgumentNullException | If unit is null. |
IList<Unit> FindConvertibleUnits |
( |
string |
unitSymbol | ) |
|
Return all units that are convertible with the unit of the specified symbol.
- Parameters
-
unitSymbol | Symbol of unit to consider. Null if unitless. |
- Returns
- All convertible units. Never null.
Return all quantities that includes the specified unit.
- Parameters
-
unit | Unit to consider. Non-null. |
- Returns
- Requested quantities. Never null.
- Exceptions
-
ArgumentNullException | If unit is null. |
IList<Quantity> FindQuantities |
( |
string |
unitSymbol | ) |
|
Return all quantities that includes the unit of the specified symbol.
- Parameters
-
unitSymbol | Unit symbol of unit to consider. Null if unitless. |
- Returns
- Requested quantities. Never null.
Quantity FindQuantity |
( |
string |
quantityName | ) |
|
Find quantity of the given name.
- Parameters
-
quantityName | Name of quantity to find. Non-null. |
- Returns
- Requested quantity or null if not found.
- Exceptions
-
ArgumentNullException | If quantityName is null. |
Find quantity of the specified unit.
Note that a unit may be contained in multiple quantities. This method is convenient if the client knows that the unit exists in one quantity only. If it exists in more than one quantity, the first one encountered is returned.
- Parameters
-
unit | Unit to consider. Non-null. |
- Returns
- Requested quantity or null if none found.
- Exceptions
-
ArgumentNullException | If unit is null. |
Unit FindUnit |
( |
string |
unitSymbol | ) |
|
Find corresponding unit instance for the given unit symbol.
The alias mapping is considered, and units are searched both case sensitive and case insensitive.
- Parameters
-
unitSymbol | Unit symbol to find unit for. May be null for unitless. |
- Returns
- Associated unit, or null if not found.
string GetDisplaySymbol |
( |
Unit |
unit | ) |
|
Return the display symbol for the given unit.
- Parameters
-
unit | Unit to get display symbol of. As a convenience for the client, null is allowed, in case an empty string is returned. |
- Returns
- Display symbol of specified unit. Empty string if unitless. Never null.
string GetDisplaySymbol |
( |
string |
unitSymbol | ) |
|
Return the display symbol for the given unit.
- Parameters
-
unitSymbol | Unit symbol of the unit to get display symbol of. Non-null. |
- Returns
- Display symbol of specified unit. Null if unitless.
Return the sole instance of this class.
- Returns
- The sole instance of this class. Never null.
Return all quantities known by this unit manager.
- Returns
- All quantities. Never null.
void SetDisplaySymbol |
( |
string |
unitSymbol, |
|
|
string |
displaySymbol |
|
) |
| |
Set the specified display symbol for the given unit symbol.
- Parameters
-
unitSymbol | Official unit symbol. Non-null. |
displaySymbol | Associated display symbol. Non-null. |
- Exceptions
-
ArgumentNullException | If unitSymbol or displaySymbol is null. |
void SetDisplaySymbol |
( |
Unit |
unit, |
|
|
string |
displaySymbol |
|
) |
| |
Set the specified display symbol for the given unit.
- Parameters
-
unit | Unit to set display symbol of. Non-null. |
displaySymbol | Associated display symbol. Non-null. |
- Exceptions
-
ArgumentNullException | If unitSymbol or displaySymbol is null. |
The documentation for this class was generated from the following file:
- Petroware/Uom/UnitManager.cs