public static bool TryParse(string str, out Unit <T> unit) { unit = default(Unit <T>); if (str == null) { return(false); } var parts = str.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 1 && parts.Length != 2) { return(false); } if (!Operators <T> .TryParse(parts[0], out unit.Value)) { return(false); } if (parts.Length == 2) { unit.UnitId = Unit_.UnitId(parts[1]); } return(true); }
/// <summary>Parse a unit from a string</summary> public static Unit <T> Parse(string str) { if (str == null) { throw new ArgumentNullException(); } var parts = str.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 1 && parts.Length != 2) { throw new FormatException(); } return(new Unit <T>(Operators <T> .Parse(parts[0]), parts.Length == 2 ? Unit_.UnitId(parts[1]) : Unit_.NoUnitsId)); }
public bool IsUnit(string unit) => IsUnit(Unit_.UnitId(unit));
[DebuggerStepThrough] public static Unit <T> operator /(T lhs, Unit <T> rhs) { var id = Unit_.CombineUnits(Unit_.NoUnitsId, rhs.UnitId, divide: true); return(new Unit <T>(Operators <T> .Div(lhs, rhs.Value), id)); }
[DebuggerStepThrough] public static Unit <T> operator *(Unit <T> lhs, Unit <T> rhs) { var id = Unit_.CombineUnits(lhs.UnitId, rhs.UnitId, divide: false); return(new Unit <T>(Operators <T> .Mul(lhs.Value, rhs.Value), id)); }