예제 #1
0
        public static float FromString(string Value, NumberFormatInfo NumberFormat)
        {
            float num;

            if (Value == null)
            {
                return(0f);
            }
            try
            {
                long num2;
                if (Utils.IsHexOrOctValue(Value, ref num2))
                {
                    return((float)num2);
                }
                double d = DoubleType.Parse(Value, NumberFormat);
                if (((d < -3.4028234663852886E+38) || (d > 3.4028234663852886E+38)) && !double.IsInfinity(d))
                {
                    throw new OverflowException();
                }
                num = (float)d;
            }
            catch (FormatException exception)
            {
                throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", new string[] { Strings.Left(Value, 0x20), "Single" }), exception);
            }
            return(num);
        }
        public static bool FromString(string Value)
        {
            bool flag;

            if (Value == null)
            {
                Value = "";
            }
            try
            {
                long        num;
                CultureInfo cultureInfo = Utils.GetCultureInfo();
                if (string.Compare(Value, bool.FalseString, true, cultureInfo) == 0)
                {
                    return(false);
                }
                if (string.Compare(Value, bool.TrueString, true, cultureInfo) == 0)
                {
                    return(true);
                }
                if (Utils.IsHexOrOctValue(Value, ref num))
                {
                    return(num > 0L);
                }
                flag = !(DoubleType.Parse(Value) == 0.0);
            }
            catch (FormatException exception)
            {
                throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", new string[] { Strings.Left(Value, 0x20), "Boolean" }), exception);
            }
            return(flag);
        }
예제 #3
0
파일: LongType.cs 프로젝트: ForNeVeR/pnet
 // Convert a string into a long value.
 public static long FromString(String Value)
 {
     if (Value != null)
     {
         try
         {
             long lvalue;
             if (TryConvertHexOct(Value, out lvalue))
             {
                 return(lvalue);
             }
             return(Convert.ToInt64
                        (Math.Round(DoubleType.Parse(Value))));
         }
         catch (OverflowException)
         {
             throw new InvalidCastException
                       (String.Format
                           (S._("VB_InvalidCast"),
                           "System.String", "System.Int64"));
         }
     }
     else
     {
         return(0);
     }
 }
예제 #4
0
 // Convert a string into a byte value.
 public static byte FromString(String Value)
 {
     if (Value != null)
     {
         try
         {
             long lvalue;
             if (LongType.TryConvertHexOct(Value, out lvalue))
             {
                 return(checked ((byte)lvalue));
             }
             return(Convert.ToByte
                        (Math.Round(DoubleType.Parse(Value))));
         }
         catch (OverflowException)
         {
             throw new InvalidCastException
                       (String.Format
                           (S._("VB_InvalidCast"),
                           "System.String", "System.Byte"));
         }
     }
     else
     {
         return(0);
     }
 }
예제 #5
0
 // Convert a string into a boolean value.
 public static bool FromString(String Value)
 {
     if (Value == null)
     {
         Value = String.Empty;
     }
     try
     {
         return(Boolean.Parse(Value));
     }
     catch (FormatException)
     {
         return(DoubleType.Parse(Value) != 0.0);
     }
 }
        public static int FromString(string Value)
        {
            int num;

            if (Value == null)
            {
                return(0);
            }
            try
            {
                long num2;
                if (Utils.IsHexOrOctValue(Value, ref num2))
                {
                    return((int)num2);
                }
                num = (int)Math.Round(DoubleType.Parse(Value));
            }
            catch (FormatException exception)
            {
                throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", new string[] { Strings.Left(Value, 0x20), "Integer" }), exception);
            }
            return(num);
        }