System.Xml.XmlConvert.ToXPathDouble C# (CSharp) Method

ToXPathDouble() static private method

static private ToXPathDouble ( Object o ) : Double
o Object
return Double
        internal static Double ToXPathDouble(Object o)
        {
            string str = o as string;
            if (str != null)
            {
                str = TrimString(str);
                if (str.Length != 0 && str[0] != '+')
                {
                    double d;
                    if (Double.TryParse(str, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo, out d))
                    {
                        return d;
                    }
                }
                return Double.NaN;
            }
            if (o is double)
            {
                return (double)o;
            }
            if (o is bool)
            {
                return ((bool)o) ? 1.0 : 0.0;
            }
            try
            {
                return Convert.ToDouble(o, NumberFormatInfo.InvariantInfo);
            }
            catch (FormatException)
            {
            }
            catch (OverflowException)
            {
            }
            catch (ArgumentNullException) { }
            return Double.NaN;
        }