コード例 #1
0
        /// <summary>
        ///   returns the string as a unint
        /// </summary>
        /// <param name="value"> uint </param>
        /// <returns> </returns>
        public static uint AsUint(this string value)
        {
            if (value.Trim() == "")
            {
                return(0);
            }
            if (!IsNumeric(value))
            {
                try
                {
                    string   p = value;
                    tsObject t = new tsObject(value);
                    value = t._mSimObjectId.AsString();
                    //dnTorque.self.Warn("Object Name  '" + p + "' was passed instead of the object ID to asUInt, performance loss.");
                }
                catch (Exception)
                {
                }
            }
            uint v;

            if (uint.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en"), out v))
            {
                return(v);
            }

            int i;

            if (int.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en"), out i))
            {
                return((uint)i);
            }
            throw new Exception("Failed to cast string to uint");
        }
コード例 #2
0
        /// <summary>
        ///   returns the string as a unint
        /// </summary>
        /// <param name="value"> uint </param>
        /// <returns> </returns>
        public static uint AsUint(this string value)
            {
            if (value.Trim() == "")
                return 0;
            if (!IsNumeric(value))
                try
                    {
                    string p = value;
                    tsObject t = new tsObject(value);
                    value = t._mSimObjectId.AsString();
                    //dnTorque.self.Warn("Object Name  '" + p + "' was passed instead of the object ID to asUInt, performance loss.");
                    }
                catch (Exception)
                    {
                    }
            uint v;
            if (uint.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en"), out v))
                return v;

            int i;
            if (int.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en"), out i))
                return (uint) i;
            throw new Exception("Failed to cast string to uint");
            }
コード例 #3
0
        /// <summary>
        ///   returns the string as a int.
        /// </summary>
        /// <param name="value"> </param>
        /// <returns> int </returns>
        public static int AsInt(this string value)
            {
            if (value.Trim() == "")
                return 0;
            if (value.ToLower() == "false")
                return 0;
            if (value.ToLower() == "true")
                return 1;
            if (value == "")
                return 0;
            if (!IsNumeric(value))
                try
                    {
                    string p = value;
                    tsObject t = new tsObject(value);
                    value = t._mSimObjectId.AsString();
                    //dnTorque.self.Warn("Object Name  '" + p + "' was passed instead of the object ID to asInt, performance loss.");
                    }
                catch (Exception)
                    {
                    }
            int i;
            if (int.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en"), out i))
                return i;

            double d;
            if (double.TryParse(value, out d))
                {
                return (int) d;
                }

            throw new Exception("Failed to cast string to int");
            }