/// <summary> /// Parses the specified format. /// </summary> /// <param name="s">The string</param> /// <returns>Returns the value.</returns> public override object Parse(string s) { bool flag; DateTime time; if ((s == null) || (s == string.Empty)) { return(null); } string str = NumberHelper.FixJapaneseChars(s); if (bool.TryParse(s, out flag)) { return((bool)flag); } if ((this.validDateTimeFormatString != null) && DateTime.TryParseExact(str, this.validDateTimeFormatString, (IFormatProvider)this.DateTimeFormatInfo, (DateTimeStyles)DateTimeStyles.NoCurrentDateDefault, out time)) { if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1)) { return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond)); } return(time); } if (this.ExactlyMatch || !DateTime.TryParse(str, (IFormatProvider)this.DateTimeFormatInfo, (DateTimeStyles)DateTimeStyles.NoCurrentDateDefault, out time)) { return(null); } if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1)) { return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond)); } return(time); }
/// <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); }
/// <summary> /// Parses the specified format. /// </summary> /// <param name="s">The string.</param> /// <returns>Returns the value.</returns> public override object Parse(string s) { if ((s == null) || (s == string.Empty)) { return(null); } s = NumberHelper.FixJapaneseChars(s); bool flag = false; int index = s.IndexOf("-"); if ((index > 0) && !DefaultTokens.IsEquals(s[index - 1], DefaultTokens.ExponentialSymbol, true)) { flag = true; } List <string> list = new List <string>(new string[] { "/", ":", "." }); list.Remove(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); bool flag2 = false; if (flag) { flag2 = true; } if (!flag2) { foreach (string str in list) { if (s.Contains(str)) { flag2 = true; break; } } } if (flag2) { DateTime time; if (DateTime.TryParseExact(s, GeneralMonthDay, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } if (DateTime.TryParseExact(s, generalYearMonth, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } if (DateTime.TryParseExact(s, GeneralYearMonthDay, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } if (DateTime.TryParseExact(s, AlternativeYearMonthDay, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } if (DateTime.TryParseExact(s, generalHourMinute, null, ((DateTimeStyles)DateTimeStyles.NoCurrentDateDefault) | ((DateTimeStyles)DateTimeStyles.AllowWhiteSpaces), out time)) { if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1)) { return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond)); } return(time); } if (DateTime.TryParseExact(s, generalHourMinuteSecond, null, ((DateTimeStyles)DateTimeStyles.NoCurrentDateDefault) | ((DateTimeStyles)DateTimeStyles.AllowWhiteSpaces), out time)) { if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1)) { return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond)); } return(time); } if (DateTime.TryParseExact(s, generalHourMinuteSecondSubSecond, null, ((DateTimeStyles)DateTimeStyles.NoCurrentDateDefault) | ((DateTimeStyles)DateTimeStyles.AllowWhiteSpaces), out time)) { if (((time.Year == 1) && (time.Month == 1)) && (time.Day == 1)) { return(new TimeSpan(0, time.Hour, time.Minute, time.Second, time.Millisecond)); } return(time); } if (DateTime.TryParseExact(s, GeneralHourMinuteWithDate, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } if (DateTime.TryParseExact(s, GeneralHourMinuteSecondWithDate, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } if (DateTime.TryParseExact(s, GeneralHourMinuteSecondSubSecondWithDate, null, (DateTimeStyles)DateTimeStyles.AllowWhiteSpaces, out time)) { return(time); } } string str2 = s; bool? nullable = null; if (str2.Substring(0, 1) == DefaultTokens.NegativeSign) { nullable = true; } else if (str2.Substring(0, 1) == DefaultTokens.PositiveSign) { nullable = false; } bool flag3 = false; if ((nullable.HasValue && (str2.Length > 3)) && ((str2[1] == DefaultTokens.LeftParenthesis) && (str2[str2.Length - 1] == DefaultTokens.RightParenthesis))) { flag3 = true; } if (nullable.HasValue && flag3) { string str3 = s.Remove(0, 1); object obj2 = this.DigitalFormat.Parse(str3); if (obj2 == null) { return(s); } if (obj2 is double) { if (nullable.Value) { return((double)-Math.Abs((double)((double)obj2))); } return((double)Math.Abs((double)((double)obj2))); } if (!(obj2 is int)) { return(obj2); } if (nullable.Value) { return((int)-Math.Abs((int)((int)obj2))); } return((int)Math.Abs((int)((int)obj2))); } object obj3 = this.DigitalFormat.Parse(s); if (obj3 != null) { return(obj3); } return(s); }