ConversionCache Class

Singleton that contains the cache of conversion factors used throughout the Quantitative assembly.

Definition

Namespace: InnerDrive.Quantitative
Assembly: InnerDrive.Quantitative (in InnerDrive.Quantitative.dll) Version: 5.2.9017.0
C#
public class ConversionCache
Inheritance
Object    ConversionCache

Remarks

Implementors of Unit classes are advised to populate the Conversions list with at least the minimum conversion factors required to use the unit.

Example

This is a typical use of the ConversionCache class (taken from the Area.ConvertTo(Unit) member). Notice that the conversion factors are "lazy-loaded" i.e., the units are not registered with the cache until a conversion actually takes place.
C#
var cache = ConversionCache.Instance;
cache.Register(Unit);
cache.Register(target);

double factor = 0d;
double converted = double.NaN;

Type sourceType = Unit.GetType();
Type targetType = target.GetType();
if (cache.Exists(sourceType, targetType))
{
    factor = cache.GetFactor(sourceType, targetType);
    converted = Value * factor;
}
else if (cache.Exists(sourceType, typeof(MeterSquare)))
{
    double meterFactor = cache.GetFactor(sourceType, typeof(MeterSquare));
    double meters = this.Value * meterFactor;
    factor = cache.GetFactor(typeof(MeterSquare), targetType);
    converted = meters * factor;
}

return new Area(converted, target);

Properties

Instance Gets the running instance of ConversionCache.
Registrations Returns a read-only copy of the internally-held list of registrations.

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Exists Gets an indication of whether a conversion exists between the Type of Unit in sourceType to targetType.
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetFactor Gets the factor by which a measurement in one Unit must be multiplied to convert it to another Unit of the same measurement.
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
IsRegistered Gets an indication of whether a particular Type is registered in the cache.
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Register Retrieves the conversion factors from a Unit and adds them to the cache, along with their inverse factors.
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also