Dahomey.ExpressionEvaluator
Dahomey.ExpressionEvaluator copied to clipboard
Add and use function of some variables
Hello! First of all, thank you for the ExpressionEvaluator, it save a lot of time I have one problem with adding new function with some variables and use it. I see the ExpressionParser has public void RegisterFunction(string functionName, Delegate function) { functions[functionName] = function; }
Okey, I want to write function standard deviation , double StDev(double[] array). I`m creating new Delegate,
public class MethodsContainer { public double StDev(double[] array) { double result = 0;// do some with array; return result; } }
public class DelegateCreator
{
public Delegate CreateNew()
{
MethodsContainer container = new MethodsContainer();
MethodInfo method = container.GetType().GetMethod("StDev");
var newDelegate = Delegate.CreateDelegate(typeof(Func<double[], double>), container, method);
return newDelegate;
}
}
then register it through RegisterFunction. What i need to do next time? Please, provide example if it`s possible
Have a good day!