internal static TimeSpan ParseExactMultiple(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles) { TimeSpanResult result = new TimeSpanResult(); result.Init(TimeSpanThrowStyle.All); if (!TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref result)) { throw result.GetTimeSpanParseException(); } return result.parsedTimeSpan; }
internal static TimeSpan Parse(string input, IFormatProvider formatProvider) { TimeSpanResult result = new TimeSpanResult(); result.Init(TimeSpanThrowStyle.All); if (!TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref result)) { throw result.GetTimeSpanParseException(); } return result.parsedTimeSpan; }
internal static Boolean TryParseExactMultiple(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result) { TimeSpanResult parseResult = new TimeSpanResult(); parseResult.Init(TimeSpanThrowStyle.None); if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult)) { result = parseResult.parsedTimeSpan; return true; } else { result = default(TimeSpan); return false; } }
internal static TimeSpan ParseExactMultiple(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles) { TimeSpanResult parseResult = new TimeSpanResult(); parseResult.Init(TimeSpanThrowStyle.All); if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult)) { return parseResult.parsedTimeSpan; } else { throw parseResult.GetTimeSpanParseException(); } }
internal static Boolean TryParse(String input, IFormatProvider formatProvider, out TimeSpan result) { TimeSpanResult parseResult = new TimeSpanResult(); parseResult.Init(TimeSpanThrowStyle.None); if (TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref parseResult)) { result = parseResult.parsedTimeSpan; return true; } else { result = default(TimeSpan); return false; } }
// ---- SECTION: internal static methods called by System.TimeSpan ---------* // // [Try]Parse, [Try]ParseExact, and [Try]ParseExactMultiple // // Actions: Main methods called from TimeSpan.Parse #region ParseMethods internal static TimeSpan Parse(String input, IFormatProvider formatProvider) { TimeSpanResult parseResult = new TimeSpanResult(); parseResult.Init(TimeSpanThrowStyle.All); if (TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref parseResult)) { return parseResult.parsedTimeSpan; } else { throw parseResult.GetTimeSpanParseException(); } }
// // TryParseExactMultipleTimeSpan // // Actions: Common private ParseExactMultiple method called by both ParseExactMultiple and TryParseExactMultiple // private static Boolean TryParseExactMultipleTimeSpan(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (input == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input)); return false; } if (formats == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(formats)); return false; } if (input.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } if (formats.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } // // Do a loop through the provided formats and see if we can parse succesfully in // one of the formats. // for (int i = 0; i < formats.Length; i++) { if (formats[i] == null || formats[i].Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } // Create a new non-throwing result each time to ensure the runs are independent. TimeSpanResult innerResult = new TimeSpanResult(); innerResult.Init(TimeSpanThrowStyle.None); if(TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref innerResult)) { result.parsedTimeSpan = innerResult.parsedTimeSpan; return true; } } result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return (false); }
private static bool TryParseExactMultipleTimeSpan(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (input == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input"); return false; } if (formats == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats"); return false; } if (input.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } if (formats.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } for (int i = 0; i < formats.Length; i++) { if ((formats[i] == null) || (formats[i].Length == 0)) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier"); return false; } TimeSpanResult result2 = new TimeSpanResult(); result2.Init(TimeSpanThrowStyle.None); if (TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref result2)) { result.parsedTimeSpan = result2.parsedTimeSpan; return true; } } result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan"); return false; }
internal static bool TryParseExactMultiple(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result) { TimeSpanResult result2 = new TimeSpanResult(); result2.Init(TimeSpanThrowStyle.None); if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref result2)) { result = result2.parsedTimeSpan; return true; } result = new TimeSpan(); return false; }
internal static bool TryParse(string input, IFormatProvider formatProvider, out TimeSpan result) { TimeSpanResult result2 = new TimeSpanResult(); result2.Init(TimeSpanThrowStyle.None); if (TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref result2)) { result = result2.parsedTimeSpan; return true; } result = new TimeSpan(); return false; }