From 8ec43230a795b0d249b9779a67b4b59ae1b7b79d Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 20 Feb 2020 21:24:27 +0100 Subject: [PATCH] Improve JS value converter to support object target type --- .../Services/JavaScriptExpressionEvaluator.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scripting/Elsa.Scripting.JavaScript/Services/JavaScriptExpressionEvaluator.cs b/src/scripting/Elsa.Scripting.JavaScript/Services/JavaScriptExpressionEvaluator.cs index 85482b5d0f..b1faa5faca 100644 --- a/src/scripting/Elsa.Scripting.JavaScript/Services/JavaScriptExpressionEvaluator.cs +++ b/src/scripting/Elsa.Scripting.JavaScript/Services/JavaScriptExpressionEvaluator.cs @@ -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))