Пример #1
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// The object value.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var unixTotalSeconds = reader.Value.SafeToString().ObjectToNullableInt64();

            if (unixTotalSeconds.HasValue)
            {
                return(CommonExtension.UnixMillisecondsToDateTime(unixTotalSeconds * 1000, DateTimeKind.Utc));
            }

            return(null);
        }
 /// <summary>
 /// Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="existingValue">The existing value of object being read.</param>
 /// <param name="serializer">The calling serializer.</param>
 /// <returns>
 /// The object value.
 /// </returns>
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (objectType.IsNullable())
     {
         var unixTotalSeconds = reader.Value.SafeToString().ObjectToNullableInt64();
         return(unixTotalSeconds.HasValue ? CommonExtension.UnixMillisecondsToDateTime(unixTotalSeconds.Value * MagnificationByMillisecond, DateTimeKind.Utc) as DateTime? : null);
     }
     else
     {
         var unixTotalSeconds = reader.Value.SafeToString().ObjectToInt64();
         return(CommonExtension.UnixMillisecondsToDateTime(unixTotalSeconds * MagnificationByMillisecond, DateTimeKind.Utc));
     }
 }