public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string text = value as string;
if (text != null)
{
text = text.Trim();
if (text.Length == 0)
{
return DateTimeOffset.MinValue;
}
try
{
// See if we have a culture info to parse with. If so, then use it.
//
DateTimeFormatInfo formatInfo = null;
if (culture != null)
{
formatInfo = (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo));
}
if (formatInfo != null)
{
return DateTimeOffset.Parse(text, formatInfo);
}
else
{
return DateTimeOffset.Parse(text, culture);
}
}
catch (FormatException e)
{
throw new FormatException(SR.Format(SR.ConvertInvalidPrimitive, (string)value, nameof(DateTimeOffset)), e);
}
}
return base.ConvertFrom(context, culture, value);
}