nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
309 stars 55 forks source link

Support for dynamic types like expando object #36

Open PeterHagen opened 3 years ago

PeterHagen commented 3 years ago

I was testing Lambdaparser.eval() to handle user expression, where values are added to an expandoObject. This way I could create a dynamic object that contains properties which can be used in the expression. But it seems that expandoObjects and dynamic objects are not supported. Here is a snippet of my unit test with the ExpandoObject:

var lambdaParser = new LambdaParser();
var varContext = new Dictionary<string, object>(); 

dynamic dynamicDiplomas = new ExpandoObject();
dynamicDiplomas.ODB = true; /* this should come from a DB */
dynamicDiplomas.IDB = null;
varContext["diplomas"] = dynamicDiplomas;

expression = "diplomas.ODB || diplomas.IDB != null";

// MissingMemberException
Assert.Throws<System.Reflection.TargetInvocationException>(() => lambdaParser.Eval(expression, varContext));

Is this a known limitation?