Access Expression.Parameters in EvaluateParameter event?

Topics: New Features
Mar 2, 2011 at 3:13 AM

Sometimes, accessing Expression.Parameters in EvaluateParameter event may be very usefual. eg.

List<Dictionary <string, double>> params_list;]
//init ...
Dictionary <string, double> params = new Dictionary <string, double>();
params["A"] = 1;
params["B"] = 2;
params_list.Add(params);
params["A"] =3;
params["B"] = 4;
params_list.Add(params);
//...list add more
Expression expr = new Expression("A+B");
expr.EvaluateParameter += delegate (string name, ParameterArgs arg)
{
    args.Result = params_list[0][name]; //index should be dynamic
}
double result = expr.Evaluate();

As the snippet show above, I can evaluate the value associated with the first item of params_list. if we can access expr.Parameters in the delegate, maybe wo can do this

expr.EvaluateParameter += delegate (string name, ParameterArgs arg)
{
    int index = arg.Parameters["index"];
    args.Result = params_list[index][name];
}
expr.Parameters["index"].Value = 0;
double result = expr.Evaluate();

And all needed is to add some properties to ParameterArgs class and set value before given to EvaluateParameter event delegate.