Conversion |
public void Register( Unit unit )
Exception | Condition |
---|---|
ArgumentNullException | Thrown if unit is null. |
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.
var cache = ConversionCache.Instance; cache.Register(Unit); cache.Register(target); // do conversion work here