private bool TryParseDateTime(string text, out DateTime result)
{
bool isValid = false;
result = this.ContextNow;
DateTime current = this.ContextNow;
try
{
// TempValue is used when Manipulating TextBox.Text while Value is not updated yet (used in DateTimePicker's TimePicker).
current = this.TempValue.HasValue
? this.TempValue.Value
: this.Value.HasValue ? this.Value.Value : DateTime.Parse(this.ContextNow.ToString(), this.CultureInfo.DateTimeFormat);
isValid = DateTimeParser.TryParse(text, this.GetFormatString(Format), current, this.CultureInfo, this.AutoClipTimeParts, out result);
}
catch (FormatException)
{
isValid = false;
}
if (!isValid)
{
isValid = DateTime.TryParseExact(text, this.GetFormatString(this.Format), this.CultureInfo, DateTimeStyles.None, out result);
}
if (!isValid)
{
result = (_lastValidDate != null) ? _lastValidDate.Value : current;
}
return(isValid);
}