Exemplo n.º 1
0
 /// <summary>Returns a <see langword="Long" /> value that corresponds to the specified string. </summary>
 /// <param name="Value">Required. String to convert to a <see langword="Long" /> value.</param>
 /// <returns>The <see langword="Long" /> value that corresponds to <paramref name="Value" />.</returns>
 public static long FromString(string Value)
 {
     if (Value == null)
     {
         return(0);
     }
     try
     {
         long i64Value = 0;
         if (Utils.IsHexOrOctValue(Value, ref i64Value))
         {
             return(i64Value);
         }
         return(Convert.ToInt64(DecimalType.Parse(Value, (NumberFormatInfo)null)));
     }
     catch (FormatException ex)
     {
         throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Long"), (Exception)ex);
     }
 }
Exemplo n.º 2
0
 /// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified string and number format information. </summary>
 /// <param name="Value">Required. String to convert to a <see langword="Decimal" /> value.</param>
 /// <param name="NumberFormat">A <see cref="T:System.Globalization.NumberFormatInfo" /> object that defines how numeric values are formatted and displayed, depending on the culture.</param>
 /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns>
 public static Decimal FromString(string Value, NumberFormatInfo NumberFormat)
 {
     if (Value == null)
     {
         return(Decimal.Zero);
     }
     try
     {
         long i64Value = 0;
         if (Utils.IsHexOrOctValue(Value, ref i64Value))
         {
             return(new Decimal(i64Value));
         }
         return(DecimalType.Parse(Value, NumberFormat));
     }
     catch (OverflowException ex)
     {
         throw ExceptionUtils.VbMakeException(6);
     }
     catch (FormatException ex)
     {
         throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Decimal"));
     }
 }