Show / Hide Table of Contents

Class UnitMan

Single class API for UOMs conversion. The entire system of UOMs could be defined as single XML file. Redundant conversion coefficients effectively eliminated, UnitMan is able to calculate conversion coefficients in many cases even these coefficients are not pre-defined.

Inheritance
System.Object
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace:AeroGIS.Common
Assembly:cs.temp.dll.dll
Syntax
public class UnitMan

Fields

Lists

Declaration
protected Dictionary<string, string[]> Lists
Field Value
Type Description
System.Collections.Generic.Dictionary<System.String, System.String[]>

UOMRegex

The regex defines chars which are valid for UOM labels. For example "[A-Z,a-z]".

Declaration
protected string UOMRegex
Field Value
Type Description
System.String

Properties

Description

Declaration
public string Description { get; }
Property Value
Type Description
System.String

User defined description of units system

Domains

The list of UOM domains.

Declaration
public List<string> Domains { get; }
Property Value
Type Description
System.Collections.Generic.List<System.String>

ISO639Code

Declaration
public string ISO639Code { get; }
Property Value
Type Description
System.String

ISO 639-2 three letters languge code. The value should be defined in XML definition file.

Methods

Atomize(String)

Decompose a complex UOM into atomic UOMs

Declaration
protected UnitMan.Atom[] Atomize(string AComplexSignature)
Parameters
Type Name Description
System.String AComplexSignature

UOM signature of any complexity

Returns
Type Description
UnitMan.Atom[]

Array of atomic UOMs

See Also
Recombine(UnitMan.Atom[])

Compose(String)

Compose UOM from signature which is not defined in source definition file. Find master UOMs, calculate scale, generate label. The signature could be of any complexity.

Declaration
protected UnitMan.UOM Compose(string ANewSignature)
Parameters
Type Name Description
System.String ANewSignature

A new signature

Returns
Type Description
UnitMan.UOM

Newly composed UOM. Please, note, the new UOM signature could differ on source signature.

Convert(Double, String, String)

Translate a value from one UOM to another. Source and destination UOMs should be compatible, i.e. they shall be of the same domain.

Declaration
public double Convert(double x, string ASrcSignature, string ADstSignature)
Parameters
Type Name Description
System.Double x

Any value

System.String ASrcSignature

UOM in wich the value is represented

System.String ADstSignature

UOM in which return value wil be represented

Returns
Type Description
System.Double

Source value translated into destination UOM

DomainOf(String)

Get domain name of UOM

Declaration
public string DomainOf(string ASignature)
Parameters
Type Name Description
System.String ASignature
Returns
Type Description
System.String

Farenheit2C(Double)

Unusual UOM Farenheit degree could not be converted like others

Declaration
public double Farenheit2C(double FarTemp)
Parameters
Type Name Description
System.Double FarTemp

Temperature in Farenheit degrees

Returns
Type Description
System.Double

Temperature in Celsius degrees

ForceConvert(Double, String, String)

Crete new UOMs if these UOMs are not defined and translate

Declaration
public virtual double ForceConvert(double x, string ASrcSignature, string ADstSignature)
Parameters
Type Name Description
System.Double x

Any value

System.String ASrcSignature

UOM in wich the value is represented

System.String ADstSignature

UOM in which return value wil be represented

Returns
Type Description
System.Double

Source value translated into destination UOM

GetStdUOM(StdVar)

Declaration
public string GetStdUOM(StdVar APrecVariable)
Parameters
Type Name Description
StdVar APrecVariable
Returns
Type Description
System.String

IsDefined(String)

Check if an UOM is defined in source XML. If UOM is not defined and loaded, then that does not mean it could not be converted. The conversion coefficients for undefined UOMs will be calculated if it is possible to find master UOMs

Declaration
public bool IsDefined(string ASignature)
Parameters
Type Name Description
System.String ASignature

UOM signature

Returns
Type Description
System.Boolean

True is the signature is pre-defined in source XML

LabelOf(StdVar)

Declaration
public string LabelOf(StdVar AVariable)
Parameters
Type Name Description
StdVar AVariable
Returns
Type Description
System.String

LabelOf(String)

Human readable label for UOM. If UOM signature not found in the dictionry then the signature will be returned instead label.

Declaration
public string LabelOf(string ASignature)
Parameters
Type Name Description
System.String ASignature
Returns
Type Description
System.String

Load(XmlDocument)

Load an user defined unit system from XML document.

Declaration
public virtual void Load(XmlDocument ADoc)
Parameters
Type Name Description
XmlDocument ADoc

MatchSimpleLabel(String)

Check if the simple UOM is defined by it's label. Simple UOM is UOM which consists of single atomic UOM.

Declaration
protected string MatchSimpleLabel(string ALabel)
Parameters
Type Name Description
System.String ALabel

UOM label

Returns
Type Description
System.String

If UOM is defined then UOM signature. Otherwise - empty string

NameOf(String)

Human readable name of UOM, such as "meter"

Declaration
public string NameOf(string ASignature)
Parameters
Type Name Description
System.String ASignature
Returns
Type Description
System.String

NormalizeSignature(String)

Sort signature atoms by next rules:

  1. Positive powers are going first
  2. Atoms of same exponent sign sorted in alphabet order
Declaration
protected string NormalizeSignature(string ASignature)
Parameters
Type Name Description
System.String ASignature
Returns
Type Description
System.String

The signature, sorted as above

ParseLabel(String)

Parse UOM signature using its human readable label like "m/s", "kg/m2" and so on. Simple and rational UOM labels are supported only.

Declaration
public string ParseLabel(string ALabel)
Parameters
Type Name Description
System.String ALabel

A human readable label

Returns
Type Description
System.String

UOM standard signature like "m1s-1", kg1m-2 and so on. If UOM is not matched than empty string returns.

PluralOf(String)

Human readable name of UOM in plural form, such as "meters"

Declaration
public string PluralOf(string ASignature)
Parameters
Type Name Description
System.String ASignature
Returns
Type Description
System.String

Recombine(UnitMan.Atom[])

Compose UOM signature from array of atomic UOMs

Declaration
protected string Recombine(UnitMan.Atom[] AnAtoms)
Parameters
Type Name Description
UnitMan.Atom[] AnAtoms

Array of atomic UOMs

Returns
Type Description
System.String

UOM signature

Back to top Copyright © 2015-2017 Microsoft
Generated by DocFX