Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and use function of some variables #3

Open
AleksandrShmalko opened this issue Apr 13, 2021 · 0 comments
Open

Add and use function of some variables #3

AleksandrShmalko opened this issue Apr 13, 2021 · 0 comments

Comments

@AleksandrShmalko
Copy link

AleksandrShmalko commented Apr 13, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant