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

Passing parameters to variable argument function #107

Open
mercurial-moon opened this issue Oct 30, 2023 · 0 comments
Open

Passing parameters to variable argument function #107

mercurial-moon opened this issue Oct 30, 2023 · 0 comments

Comments

@mercurial-moon
Copy link

I have wrapper that creates list's of various types.

    public static class ListWrapper
    {
        public static List<string> CreateListStr(params string[] args)
        {
            return new List<string>(args);
        }
        public static List<int> CreateListInt(params int[] args)
        {
            return new List<int>(args);
        }
        public static List<object> CreateListObj(params object[] args)
        {
            return new List<object>(args);
        }
    }

I then try to use it like this.

            ExpressionContext context = new ExpressionContext();
            context.Imports.AddType(typeof(ListWrapper), "ExpressionEngineTests");
            context.Variables["liststr"] = new string[1];
            context.Variables["listint"] = new int[1];
            context.Variables["listobj"] = new object[1];

            var dynExpStr = context.CompileDynamic("CreateListStr(liststr)"); // <- Error: Flee.PublicTypes.ExpressionCompileException: 'FunctionCallElement: Could find not function 'CreateListStr(String[])''
            var dynExpInt = context.CompileDynamic("CreateListInt(listint)");
            var dynExpObj = context.CompileDynamic("CreateListObj(listobj)");

            context.Variables["liststr"] = "\"a\", \"b\", \"c\"";
            context.Variables["listint"] = "1, 2, 3";
            context.Variables["listobj"] = "\"a\", 1, true";

            var res1 = dynExpStr.Evaluate();
            var res2 = dynExpInt.Evaluate();
            var res3 = dynExpObj.Evaluate();

However I get error at the indicated line
Flee.PublicTypes.ExpressionCompileException: 'FunctionCallElement: Could find not function 'CreateListStr(String[])''

Is there any other syntax for getting this done?

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