-
Notifications
You must be signed in to change notification settings - Fork 2
Unit Symbols
Query.UnitSymbol returns the engineer-facing display symbol for a BH.oM.Units unit member — e.g. LengthUnit.Millimeter → "mm", AreaMomentOfInertiaUnit.CentimeterToTheFourth → "cm⁴". It's a one-way lookup, unit → symbol, meant for labelling values in UI or reports. It does not parse a symbol string back into a unit.
using BH.Engine.Units;
using BH.oM.Units;
string mm = LengthUnit.Millimeter.UnitSymbol(); // "mm"
string cm4 = AreaMomentOfInertiaUnit.CentimeterToTheFourth.UnitSymbol(); // "cm⁴"
string none = LengthUnit.Undefined.UnitSymbol(); // "" - Undefined has no symbolBH.oM.Units enum members carry no symbol of their own — UnitsNet is the only thing in the stack that publishes one. UnitSymbol.cs bridges to it:
- The BHoM unit's declared type name (e.g.
LengthUnit) is matched, by name, to the UnitsNet type of the same name inUnitsNet.Units. This bridge is by name rather than by value because the two enums' underlying integer values don't agree for several quantities (LengthUnit,AngleUnit,PressureUnit, and others) — a numeric cast would silently hand back the wrong unit. - If the member's name isn't defined on the UnitsNet side —
Undefined, or anything BHoM has added since (e.g.WarpingMomentOfInertiaUnit, which UnitsNet does define, so this only bites genuinely BHoM-only members) — the lookup fails. - Otherwise, UnitsNet's abbreviation table is asked for every symbol registered for that unit, and the first (default) one is returned.
If the unit isn't found, or UnitsNet has registered no abbreviation for it, UnitSymbol returns "" and records an error — it never throws.
There is currently no supported way to go from a symbol string back to a unit — ToUnit/FromUnit (see Unit Conversion) take a BH.oM.Units enum member directly rather than a symbol.