Flee
Flee copied to clipboard
Passing parameters to variable argument function
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?