public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        var isoConverter = new IsoDateTimeConverter();
        var withTz       = (DateTimeOffset)isoConverter.ReadJson(reader, typeof(DateTimeOffset), existingValue, serializer);

        return(withTz.DateTime);
    }
Ejemplo n.º 2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var convertor = new IsoDateTimeConverter
            {
                DateTimeFormat = FORMAT
            };

            return(convertor.ReadJson(reader, objectType, existingValue, serializer));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取json
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="objectType"></param>
        /// <param name="existingValue"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var date = base.ReadJson(reader, objectType, existingValue, serializer) as DateTime?;

            if (date.HasValue)
            {
                return(dtConverter.ReadJson(reader, objectType, existingValue, serializer));
            }

            return(null);
        }
Ejemplo n.º 4
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                 JsonSerializer serializer)
 {
     try
     {
         return(_converter.ReadJson(reader, objectType, existingValue, serializer));
     }
     catch
     {
         return(existingValue);
     }
 }
Ejemplo n.º 5
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     try
     {
         var result = dtConverter.ReadJson(reader, objectType, existingValue, serializer);
         return(result);
     }
     catch (Exception)
     {
         return(Convert.ToDateTime(reader.Value));
     }
 }
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        // We'll make use of Json.NET's own IsoDateTimeConverter so
        // we don't have to re-implement everything ourselves.
        var isoConverter = new IsoDateTimeConverter();
        // Deserialise into a DateTimeOffset which will hold the
        // time and the timezone from the JSON.
        var withTz = (DateTimeOffset)isoConverter.ReadJson(reader, typeof(DateTimeOffset), existingValue, serializer);

        // Return the DateTime component. This will be the original
        // datetime WITHOUT timezone information.
        return(withTz.DateTime);
    }
Ejemplo n.º 7
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     try
     {
         DateTime result;
         // приоритетным делаем российский формат даты-вермени
         bool succeed = DateTime.TryParseExact(reader.Value.ToString(), "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture,
                                               DateTimeStyles.None, out result);
         if (!succeed)
         {
             // если времени нет, парсим просто дату
             result = DateTime.ParseExact(reader.Value.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
         }
         return(result);
     }
     catch (Exception e)
     {
         // если ничего не вышло, пробуем парсить как обычно
         return(_isoDateTimeConverter.ReadJson(reader, objectType, existingValue, serializer));
     }
 }
Ejemplo n.º 8
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     return(dtConverter.ReadJson(reader, objectType, existingValue, serializer));
 }