static bool DeserializeTimeSpan(JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) { if (tokenizer.HasSpecialChar) { tokenizer.SkipValueBody(); } else if (tokenizer.TokenIsString) { TimeSpan t; if (TryParseTime(tokenizer.Token, out t)) { value = t; return(true); } } else { double v; if (JsonConvert.TryParse(tokenizer.Token, out v)) { value = TimeSpan.FromSeconds(v); return(true); } } value = null; return(false); }
static bool DeserializeDateTime(JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) { if (tokenizer.HasSpecialChar) { tokenizer.SkipValueBody(); } else if (tokenizer.TokenIsString) { DateTime d; if (DateTime.TryParse(tokenizer.Token, CultureInfo.InvariantCulture, DateTimeStyles.None, out d)) { value = d; return(true); } } else { double v; if (JsonConvert.TryParse(tokenizer.Token, out v)) { value = ConvertUnixDateTime(v); return(true); } } value = null; return(false); }
static bool DeserializeBoolean(JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) { if (tokenizer.HasSpecialChar) { tokenizer.SkipValueBody(); } else { string t = tokenizer.Token; if (t == "false") { value = false; return(true); } if (t == "true") { value = true; return(true); } double v; if (JsonConvert.TryParse(t, out v)) { value = Math.Abs(v) >= 1 - 1e-7; return(true); } } value = null; return(false); }
static bool DeserializeInteger_string(JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) { if (tokenizer.HasSpecialChar) { tokenizer.SkipValueBody(); value = null; return(false); } value = tokenizer.Token; return(true); }
static bool DeserializeInteger_double(JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) { if (tokenizer.HasSpecialChar) { tokenizer.SkipValueBody(); } else { double v; if (JsonConvert.TryParse(tokenizer.Token, out v)) { value = v; return(true); } } value = null; return(false); }
static bool DeserializeInteger_ulong(JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) { if (tokenizer.HasSpecialChar) { tokenizer.SkipValueBody(); } else { double v; if (JsonConvert.TryParse(tokenizer.Token, out v)) { v = Math.Round(v); ulong i = unchecked ((ulong)v); bool res = v - i == 0; value = res ? (object)i : null; return(res); } } value = null; return(false); }