Skip to content

Commit

Permalink
Improve JS value converter to support object target type
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed Feb 20, 2020
1 parent a9a4f78 commit 8ec4323
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ private object ConvertValue(JsValue value, Type targetType)
if (value.IsNull())
return default;

if (targetType == typeof(bool) && value.IsBoolean())
var targetIsObject = targetType == typeof(object);

if (value.IsBoolean())
return value.AsBoolean();

if (targetType == typeof(DateTime) && value.IsDate())
if ((targetIsObject || targetType == typeof(DateTime)) && value.IsDate())
return value.AsDate().ToDateTime();

if (targetType.IsNumeric() && value.IsNumber())
if ((targetIsObject || targetType.IsNumeric()) && value.IsNumber())
return Convert.ChangeType(value.AsNumber(), targetType);

if (targetType == typeof(string))
Expand Down

0 comments on commit 8ec4323

Please sign in to comment.