Exemple #1
0
 /// <summary>
 /// Parses the specified format.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>Returns the value.</returns>
 public override object Parse(string s)
 {
     s = this.TrimSpecialSymbol(s);
     if ((s != null) && (s != string.Empty))
     {
         bool   flag;
         string str = NumberHelper.FixJapaneseChars(s);
         if (bool.TryParse(s, out flag))
         {
             return((bool)flag);
         }
         bool flag2 = DefaultTokens.IsDecimal(str, this.NumberFormatInfo);
         bool flag3 = str.IndexOf(DefaultTokens.ExponentialSymbol, (StringComparison)StringComparison.CurrentCultureIgnoreCase) > -1;
         bool flag4 = (str[0] == DefaultTokens.LeftParenthesis) && (str[str.Length - 1] == DefaultTokens.RightParenthesis);
         if (this.numberFormatString != null)
         {
             double num2;
             int    count = 0;
             s = this.TrimPercentSign(s, out count);
             if (this.TryParse(s, out num2, flag3 | flag4))
             {
                 if (count > 0)
                 {
                     num2 /= 100.0 * count;
                 }
                 if ((num2 != 0.0) && (Math.Abs((double)(num2 - Math.Floor(num2))) != 0.0))
                 {
                     flag2 = true;
                 }
                 if (flag3)
                 {
                     flag2 = true;
                 }
                 if (!flag2)
                 {
                     int  num3;
                     long num4;
                     if (NumberHelper.TryInteger(num2, out num3))
                     {
                         return((int)num3);
                     }
                     if (NumberHelper.TryLong(num2, out num4))
                     {
                         return((long)num4);
                     }
                 }
                 return((double)num2);
             }
         }
     }
     return(null);
 }
Exemple #2
0
 /// <summary>
 /// Parses the specified string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>Returns the parsed object.</returns>
 public object Parse(string s)
 {
     if ((s != null) && (s != string.Empty))
     {
         if (DefaultTokens.IsDecimal(s, this.FormatProvider))
         {
             double num;
             if (double.TryParse(s, (NumberStyles)NumberStyles.Any, (IFormatProvider)this.FormatProvider, out num))
             {
                 return((double)num);
             }
         }
         else
         {
             int num2;
             if (int.TryParse(s, (NumberStyles)NumberStyles.Any, (IFormatProvider)this.FormatProvider, out num2))
             {
                 return((int)num2);
             }
         }
     }
     return(null);
 }