public static bool TryParse(string input, out Ratio result)
 {
     return TryParse(input, CultureInfo.InvariantCulture, out result);
 }
        public static bool TryParse(string input, IFormatProvider formatProvider, out Ratio result)
        {
            if (input != null)
            {
                var fractionIndex = input.IndexOf('/');

                int numerator;
                if (fractionIndex < 0)
                {
                    if (int.TryParse(input, NumberStyles.Integer, formatProvider, out numerator))
                    {
                        result = new Ratio(numerator, 1);
                        return true;
                    }
                }
                else
                {
                    int denominator;
                    if (int.TryParse(input.Substring(0, fractionIndex), NumberStyles.Integer, formatProvider, out numerator) &&
                        int.TryParse(input.Substring(fractionIndex + 1), NumberStyles.Integer, formatProvider, out denominator))
                    {
                        result = new Ratio(numerator, denominator);
                        return true;
                    }
                }
            }

            result = default(Ratio);
            return false;
        }
Exemple #3
0
 public static bool TryParse(string input, out Ratio result)
 {
     return(TryParse(input, CultureInfo.InvariantCulture, out result));
 }