Click or drag to resize

ConversionCacheRegister Method

Retrieves the conversion factors from a Unit and adds them to the cache, along with their inverse factors.

Namespace: InnerDrive.Quantitative
Assembly: InnerDrive.Quantitative (in InnerDrive.Quantitative.dll) Version: 5.0.8475.0
Syntax
C#
public void Register(
	Unit unit
)

Parameters

unit  Unit
The Unit whose conversion factors to add to the cache.
Exceptions
ExceptionCondition
ArgumentNullExceptionThrown if unit is null.
Remarks
When a Unit is registered, not only are its Conversions registered, but the inverse conversions are as well. For example, the Foot class includes a conversion factor for inches (12). When the Foot class is registered, an item will be added to the cache noting that 1 foot == 12 inches, and then a second item will be added noting that 1 inch == (1 / 12) feet.

That said, when a Unit is registered in anticipation of a conversion, both it and the reciprocal unit should be registered simultaneously. (All IDEA IMeasurable classes do this.) This ensures that reciprocal conversion factors need be defined in only one of the two units of a pair. This makes the conversions easier to maintain. For example, the Foot class defines its conversion to inches (= 12), but the Inch class doesn't. This makes the conversion factor, a whole integer, easier to work with.

If two classes define reciprocal conversions differently, the first one registered will be used, and the second will be discarded.

Classes derived from CompoundUnit are not cached in themselves; rather, their constituent parts are registered recursively. This is because each instance of a CompoundUnit derivation can have different FirstUnit and SecondUnit values at any time.

Example
All built-in IConvertibleT classes (except Temperature) have the following code in their conversion methods (see, e.g., Area.ConvertTo(Unit)):
C#
var cache = ConversionCache.Instance;
cache.Register(Unit);
cache.Register(target);

// do conversion work here
See Also