Open jamiecoh opened 5 years ago
Workaround for this issue is to add an Import with the same functionality:
public static class HelperFunctions
{
// This shouldn't be necessary - I can usually execute an objects methods directly in an expression
public static DateTime AddDays(DateTime date, int days)
{
return date.AddDays(days);
}
}
Remember to import the helper class, and then use AddDays(d,1)
as the expression
var eng = new CalculationEngine();
var ctx = new ExpressionContext();
ctx.Imports.AddType(typeof(HelperFunctions));
ctx.Variables.Add("now", DateTime.Now);
eng.Add("d", "now",ctx);
eng.Add("res", "AddDays(d,1)", ctx);
var result = eng.GetResult("res");
When using methods on
DateTime
such asAddDays
in an expression the following works as expected:However, when trying to execute
AddDays
in the following (similar) manner, you get a NRE from FLEE:This error occurs in
Flee.InternalTypes.Expression
:Here is the StackTrace