示例#1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.Integer)
            {
                throw new Exception("Unexpected token type.");
            }

            var unixTime = (long)reader.Value;

            return(UnixTimeHelper.ToDateTime(unixTime));
        }
示例#2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (false == value is DateTime)
            {
                throw new Exception("Unexpected object type.");
            }

            var dateTime = (DateTime)value;

            var unixTime = UnixTimeHelper.ToUnixTime(dateTime);

            writer.WriteValue(unixTime);
        }