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

Support delegation #102

Open
syyqdsxfdmy opened this issue Nov 8, 2022 · 1 comment
Open

Support delegation #102

syyqdsxfdmy opened this issue Nov 8, 2022 · 1 comment

Comments

@syyqdsxfdmy
Copy link

I have a custom method to receive the delegation type. The method code is as follows:
public static dynamic GREPARRAY(dynamic data, Func<dynamic, bool> func)
{
if (func==null)
{
func = item => item > 1;
}
List list = new List();
if (data is Array)
{
foreach (dynamic item in data)
{
if (func(item))
{
list.Add(item);
}
}
}
return list;
}

I try to use statements:“GREPARRAY(null,item=>item>1)”,An error occurred。
How do I call this method,thanks

@OJB78
Copy link

OJB78 commented Jan 22, 2023

Hello team!

It would be really great if we have support for delegation.
I have the follow scenario. Is there any workaround to make this work?
Thanks!

public class Test
{
    public int Method1(string str)
    {
        // Do something
        return 0;
    }

    public int Method2(string str)
    {
        // Do something different
        return 1;
    }

    public int RunTheMethod(Func<string,int> myMethodName)
    {
        // ... do stuff
        int i = myMethodName("Test");
        // ... do more stuff
        return i;
    }

    public void Init()
    {
        // This is working
        int x = RunTheMethod(Method1);
        int y = RunTheMethod(Method2);

        // This is not working
        ExpressionContext context = new ExpressionContext();
        IGenericExpression<int> e = context.CompileGeneric<int>("RunTheMethod(Method1)");
        int z = e.Evaluate();
    }
}

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

2 participants