public class ConversionCache
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);
Instance | Gets the running instance of ConversionCache. |
Registrations | Returns a read-only copy of the internally-held list of registrations. |
Equals | Determines 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. |
Finalize | Allows 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. |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
IsRegistered | Gets an indication of whether a particular Type is registered in the cache. |
MemberwiseClone | Creates 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. |
ToString | Returns a string that represents the current object. (Inherited from Object) |