public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.Value == null) { return(DateTime.MinValue); } if (!(reader.Value is string stringVal)) { throw new InvalidDateTimeException("Invalid date/time from VirusTotal. Tried to parse: " + reader.Value); } if (!ResourcesHelper.IsNumeric(stringVal)) { return(DateTime.MinValue); } //New format if (DateTime.TryParseExact(stringVal, _newDateTimeFormat, _culture, DateTimeStyles.AllowWhiteSpaces, out DateTime result)) { return(result); } //Old format if (DateTime.TryParseExact(stringVal, _oldDateTimeFormat, _culture, DateTimeStyles.AllowWhiteSpaces, out result)) { return(result); } throw new InvalidDateTimeException("Invalid date/time from VirusTotal. Tried to parse: " + stringVal); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { string stringVal = reader.Value.ToString(); if (string.IsNullOrWhiteSpace(stringVal)) { return(DateTime.MinValue); } if (!ResourcesHelper.IsNumeric(stringVal)) { return(DateTime.MinValue); } return(FromUnix(long.Parse(stringVal))); }