Esempio n. 1
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                var value = reader.Value?.ToString();

                if (objectType == typeof(FuzzyDate?))
                {
                    return(FuzzyDate.TryParse(value));
                }

                return(FuzzyDate.Parse(value));
            }
Esempio n. 2
0
        /// <summary>
        /// Parses the range from a serialized representation.
        /// </summary>
        public static FuzzyRange Parse(string raw)
        {
            if (string.IsNullOrEmpty(raw))
            {
                throw new ArgumentNullException(nameof(raw));
            }

            var parts = raw.Split("-");

            if (parts.Length != 2)
            {
                throw new ArgumentException("Incorrect range format.");
            }

            var from = !string.IsNullOrEmpty(parts[0]) ? FuzzyDate.Parse(parts[0]) : (FuzzyDate?)null;
            var to   = !string.IsNullOrEmpty(parts[1]) ? FuzzyDate.Parse(parts[1]) : (FuzzyDate?)null;

            return(new FuzzyRange(from, to));
        }
Esempio n. 3
0
 public override FuzzyDate?Parse(object value)
 {
     return(FuzzyDate.TryParse(value?.ToString()));
 }