This project is read-only.

Using farmework static methods

Apr 5, 2017 at 8:04 AM
Edited Apr 5, 2017 at 8:07 AM
I'm trying to call System.Math.Abs in my dynamic expression, but I get an error saying "Unknown identifier System".

"System.Math.Abs((oldVal - newVal) * 100) <= threshold"

oldVal, newVal and threshold is my input to the function

var oldVal = Expression.Parameter(typeof(double), "oldValue");
var newVal = Expression.Parameter(typeof(double), "newValue");
var limit = Expression.Parameter(typeof(double), "threshold");
var lambda = System.Linq.Dynamic.DynamicExpression.ParseLambda(new[] { oldVal, newVal, limit }, typeof(bool), expression);

return (bool)lambda.Compile().DynamicInvoke(new[] {oldValue, newValue, threshold});

If I remove "System." I get a parameter count mismatch error. Not sure what's going on here. Any help to resolve this is appreciated.

Apr 5, 2017 at 8:27 AM
Never mind. It was my mistake. Below fixed it

return (bool)lambda.Compile().DynamicInvoke(oldValue, newValue, threshold);