diff --git a/PowerAutomateMockUp/ExpressionParser/ValueContainer.cs b/PowerAutomateMockUp/ExpressionParser/ValueContainer.cs index 81a21ba..fd926c6 100644 --- a/PowerAutomateMockUp/ExpressionParser/ValueContainer.cs +++ b/PowerAutomateMockUp/ExpressionParser/ValueContainer.cs @@ -112,9 +112,16 @@ public ValueContainer() _value = null; } - public ValueContainer(JToken json) + public ValueContainer(JToken json, IExpressionEngine expressionEngine = null) { - var v = JsonToValueContainer(json); + if (json == null) + { + _type = ValueType.Null; + _value = null; + return; + } + + var v = JsonToValueContainer(json, expressionEngine); _type = v._type; _value = v._value; } @@ -222,24 +229,26 @@ public Dictionary AsDict() throw new PowerAutomateMockUpException("Can't get none object value container as dict."); } - private ValueContainer JsonToValueContainer(JToken json) + private ValueContainer JsonToValueContainer(JToken json, IExpressionEngine expressionEngine) { switch (json) { - case JObject jObject: + case JObject _: { var dictionary = json.ToDictionary(pair => ((JProperty) pair).Name, token => { - if (token.Children().Count() != 1) return JsonToValueContainer(token.Children().First()); + if (token.Children().Count() != 1) + return JsonToValueContainer(token.Children().First(), expressionEngine); var t = token.First; return t.Type switch { - JTokenType.String => new ValueContainer(t.Value(), true), + JTokenType.String => expressionEngine?.ParseToValueContainer(t.Value()) ?? + new ValueContainer(t.Value()), JTokenType.Boolean => new ValueContainer(t.Value()), JTokenType.Integer => new ValueContainer(t.Value()), JTokenType.Float => new ValueContainer(t.Value()), - _ => JsonToValueContainer(token.Children().First()) + _ => JsonToValueContainer(token.Children().First(), expressionEngine) }; }); @@ -260,7 +269,8 @@ private ValueContainer JsonToValueContainer(JToken json) JTokenType.Integer => new ValueContainer(jValue.Value()), JTokenType.Float => new ValueContainer(jValue.Value()), JTokenType.Null => new ValueContainer(), - JTokenType.String => new ValueContainer(jValue.Value()), + JTokenType.String => expressionEngine?.ParseToValueContainer(jValue.Value()) ?? + new ValueContainer(jValue.Value()), JTokenType.None => new ValueContainer(), JTokenType.Guid => new ValueContainer(jValue.Value().ToString()), _ => throw new PowerAutomateMockUpException(