Skip to content

v2.7.1

Choose a tag to compare

@JonathanMagnan JonathanMagnan released this 19 Jul 23:07
· 160 commits to master since this release
02b503b

Download the library here

  • ADDED: IsExpressionValue property to the VariableFactoryArgument. When true, a parameter will no longer be used from the value, the expression will be returned directly. This new option allows creating dictionary value on the fly.
var variables = new Dictionary<string, object>();
var eval = new EvalContext();

eval.VariableFactory = argument =>
{
    variables[argument.Name] = 2;
    argument.IsHandled = true;
    argument.IsExpressionValue = true;

    var dict = Expression.Constant(variables);
    var dictionaryItemPropertyInfo = typeof(IDictionary).GetProperty("Item", new[] { typeof(string) });
    Expression innerExpression = Expression.Property(dict, dictionaryItemPropertyInfo, Expression.Constant(argument.Name));
    argument.Value = Expression.Convert(innerExpression, typeof(int));
};

eval.Execute("x = 0; x = 6 + x;", variables);
var value = variables["x"];
var counter = variables.Count;

Trial unlocked for the current month (July)