static object ConvertSimpleValue(JsonLiteObjectBase value, Type propertyType) { JsonLiteValue jsonValue = value as JsonLiteValue; if (jsonValue == null) { throw new JsonLiteDeserializationException(); } if (propertyType == typeof(TimeSpan)) { return(TimeSpan.Parse(jsonValue.Value, CultureInfo.InvariantCulture)); } return(Convert.ChangeType(jsonValue.Value, propertyType, CultureInfo.InvariantCulture)); }
static object ConvertToObject(JsonLiteObjectBase value, Type propertyType) { JsonLiteObject jsonValue = value as JsonLiteObject; if (jsonValue == null) { JsonLiteValue val = value as JsonLiteValue; if (val != null && val.Value == "null") { return(null); } throw new JsonLiteDeserializationException(); } object instance = Activator.CreateInstance(propertyType); if (instance != null) { ApplyProperties(value, instance); } return(instance); }