-
Notifications
You must be signed in to change notification settings - Fork 11
Custom units
Your options for creating units not already in EngineeringUnits:
- Create a new Issue and ask for your new unit to be added.
- Create a Pull request where you already have added the units yourself
- Add the units in your own project
Fork a new version of EngineeringUnits and download a clone of it.
Go to the CodeGen
project
Insert the name of your new unit into GetListOfCombinedUnits()
:
Run the CodeGen Project. Your new unit has been added to the folder EngineeringUnits-> CombinedUnits -> 'NameOfYourUnit'
In the newly created folder open the file named YourUnitEnum.cs
Add the quantities of your unit. Here you can get inspiration from other units already added.
example the EnergyCostUnit
:
public static readonly EnergyCostUnit SI = new(CostUnit.SI, EnergyUnit.SI);
public static readonly EnergyCostUnit DollarPerJoule = new(CostUnit.USDollar, EnergyUnit.Joule);
public static readonly EnergyCostUnit DollarPerKilojoule = new(CostUnit.USDollar, EnergyUnit.Kilojoule);
public static readonly EnergyCostUnit DollarPerMegajoule = new(CostUnit.USDollar, EnergyUnit.Megajoule);
public static readonly EnergyCostUnit DollarPerGigajoule = new(CostUnit.USDollar, EnergyUnit.Gigajoule);
public static readonly EnergyCostUnit DollarPerKilowattHour = new(CostUnit.USDollar, EnergyUnit.KilowattHour);
public static readonly EnergyCostUnit DollarPerMegawattHour = new(CostUnit.USDollar, EnergyUnit.MegawattHour);
public EnergyCostUnit(CostUnit cost, EnergyUnit energy)
{
var localUnit = cost / energy;
var localSymbol = $"{cost}/{energy}";
Unit = new UnitSystem(localUnit, localSymbol);
}
It can be created by combining EnergyUnit
and CostUnit
Now you have to work out how to combine other units into your new unit.
If you would like the unit to be a part of the official EngineeringUnits nuget package, you can create a pull request. If you just want to have your unit as part of your own project, you can copy the newly created folder into your own project.
Exemple: looking to extent LengthCost.
Locate the folder EngineeringUnits-> CombinedUnits -> LengthCost
and open LengthCostEnum.cs
Look at the structure of the available constructors. In this case:
In your own project create a static class with a static property:
Call your new unit like this: