是否可以将函数定义为脚本,然后运行它?
我正在努力实现这样的目标:
//defined in a namespace
public class Params{public string input { get; set; }}
string script = "string TryToUpper(string input){ return input.ToUpper(); }";
var v = CSharpScript.Create(script, globalsType: typeof(Params) );
// what to do to execute TryToUpper and get "GIUSEPPE" back?
var val = v.RunAsync(???);发布于 2017-10-02 11:47:09
您必须在脚本中做两件事:首先,定义函数,然后实际运行它并返回它的结果。如下所示:
public class Params
{
public string input;
}
Params globals = new Params();
globals.input = "some lowercase text";
string script = "string TryUpper(string str) { return str.ToUpper(); } return TryUpper(input);";
string result = await CSharpScript.EvaluateAsync<string>(script, globals: globals);https://stackoverflow.com/questions/46524379
复制相似问题