Exemplo n.º 1
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="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 (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            switch (reader.TokenType)
            {
            case JsonToken.Null:
                return(null);

            case JsonToken.Date:
                if (reader.Value is DateTime)
                {
                    return(new EssentialsPartialDate((DateTime)reader.Value));
                }
                throw new JsonSerializationException("Value doesn't match an instance of DateTime: " + reader.Value.GetType());

            case JsonToken.String:
                if (String.IsNullOrWhiteSpace(reader.Value + ""))
                {
                    return(null);
                }
                return(EssentialsPartialDate.Parse(reader.Value + ""));

            default:
                throw new JsonSerializationException("Unexpected token type: " + reader.TokenType);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is EssentialsPartialDate))
            {
                return;
            }
            EssentialsPartialDate date = (EssentialsPartialDate)value;

            writer.WriteValue(date.ToString());
        }
        internal static object ToFormat(EssentialsPartialDate value, TimeFormat format)
        {
            switch (format)
            {
            case TimeFormat.Iso8601:
                return(value.ToString());

            default:
                throw new ArgumentException("Unsupported format " + format, nameof(format));
            }
        }
Exemplo n.º 4
0
 public Sample(int year, int month, int day)
 {
     PartialDate = new EssentialsPartialDate(year, month, day);
 }
Exemplo n.º 5
0
 public Sample(int year)
 {
     PartialDate = new EssentialsPartialDate(year);
 }