I'm trying to use NCalc to parse some formula from JSON files.
However sometimes I'm needing to reference another object via GUID and get that objects formula:
public class FooObject
{
NCalc.Expression expression;
double Value;
public void SetValue()
{Value = (double)expression.Evaluate()} //this throws "Value was either too large or too small for a Double."
public FooObject()
{ expression = new NCalc.Expression("TechData(b8ef73c7-2ef0-445e-8461-1e0508958a0e)")}
expression.EvaluateFunction += NCalcFunctions;
}
}
public static void NCalcFunctions(string name, FunctionArgs args)
{
if (name == "TechData") //breakpoint shows we never get this far
{
Guid techGuid = new Guid(args.Parameters[0].ToString());
TechSD techSD = _staticData.Techs[techGuid]; //this returns an TechSD object that matches the given guid.
args.Result = techSD.DataExpression;//returns an NCalc expression from the techSD
}
}
SetValue()
throws an exception (Value was either too large or too small for a Double), and the custom function never gets called.
I'm suspecting it's trying to parse the GUID. Would this be correct? Is what I'm trying to do possible with NCalc? is there a better tool?