Пример #1
0
        public static bool CanConvert(string from, string to, double fromPower = 1, double toPower = 1)
        {
            if (toPower != fromPower)
            {
                return(false);
            }
            if (from == to)
            {
                return(true);
            }
            double m;

            return(UnitMultipliers.TryGetValue(from + "-" + to, out m) || UnitMultipliers.TryGetValue(to + "-" + from, out m));
        }
Пример #2
0
        public static double GetUnitMultiplier(string from, string to)
        {
            double multiplier;

            if (from == to)
            {
                return(1);
            }
            if (UnitMultipliers.TryGetValue(from + "-" + to, out multiplier))
            {
                return(multiplier);
            }
            if (UnitMultipliers.TryGetValue(to + "-" + from, out multiplier))
            {
                return(1 / multiplier);
            }
            throw new InvalidConversionException("Could not find unit multiplier for " + from + " to " + to);
        }