I have a WebAPI property like below.
[JsonConverter(typeof(DateFormatConverter), "mm-dd-yyyy")]
public DateTime? StartDate { get; set; }
And DateFormatConverter
public class DateFormatConverter : IsoDateTimeConverter
{
/// <summary>
/// Format of the date
/// </summary>
/// <param name="format"></param>
public DateFormatConverter(string format)
{
DateTimeFormat = format;
}
}
if I pass following dates:
1- 10-20-2019
2- 2019-10-17T00:14:35.8384165-04:00
For example following should throw exception:
string stringDate = "\"2019-10-17T00:14:35.8384165-04:00\"";
DateTime deserializeObject = JsonConvert.DeserializeObject<DateTime>(stringDate, new DateFormatConverter("mm-dd-yyyy"));
both are getting parsed. But I would like to throw exception on second one.
How can I handle this in DateFormatConverter
?