Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
 public bool IsUnit(string unit) => IsUnit(Unit_.UnitId(unit));