internal static object FixValueTypes(object value) { if (value == null) { return(null); } Text txt; Number n; Date d; Time t; Bool b; if (Text.TryCast(value, out txt)) { value = (txt ?? "").TrimEnd().ToString(); } else if (Number.TryCast(value, out n)) { var dec = n.ToDecimal(); var lng = (long)dec; if (dec != lng) { value = dec; } else { value = lng; } } else if (Date.TryCast(value, out d)) { if (d == Date.Empty) { value = null; } else { value = d.ToString("YYYY-MM-DD"); } } else if (Time.TryCast(value, out t)) { value = t.ToString("HH:MM:SS"); } else if (Bool.TryCast(value, out b)) { value = b.ToBoolean(); } return(value); }