Example #1
0
        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);
        }
Example #2
0
        /// <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));
        }
Example #3
0
 public bool IsUnit(string unit) => IsUnit(Unit_.UnitId(unit));
Example #4
0
        [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));
        }
Example #5
0
        [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));
        }