Custom Units - LZorglub/Measure GitHub Wiki
#Custom Units
You can create new unit in your own library. The easy way is to inherited your class from derived unit.
class Calorie : Joule
{
public Calorie()
{
this._symbol = "cal";
this._baseConverter = new MultiplyConverter(4.184);
}
}
Your custom assembly must be register in Unit class to be able to parse your new unit symbol
Unit.LoadAssembly(Assembly.GetExecutingAssembly());
##Custom product unit
When your unit is the result of the product of two units you need to inherited from ProductUnit
or ProductMetricBaseUnit
. Exponent and symbol of the unit can be defined in the constructor.
public class CustomNewton : ProductMetricBaseUnit {
public Newton() : base(new Acceleration(), Afk.Measure.Units.System.SI.GRAM) {
this.Exponent = 1;
_symbol = "N";
}
}
ProductMetricBaseUnit
can be prefixed by a metric SI prefix.