传递数组作为CSharpScript的输入参数



我尝试通过CSharpScript运行方法。

方法:

public class TaskSolution 
{ 
public int[] Calculate(int[] inputValue) 
{
return inputValue;
}
}

我尝试了这个解决方案:

var script = CSharpScript.Create(solution.Code);
var input = new int[3] { 1, 2, 3 };
var call = await script.ContinueWith<int[]>($"new TaskSolution().Calculate({input})").RunAsync();

但是它抛出Microsoft.CodeAnalysis.Scripting.CompilationErrorException,里面有文本"(1,43): error CS0443: Syntax error; value expected",没有更多的信息。

当我运行类似的方法,但有简单的输入参数(如int或string) -它运行成功。但是我在使用数组时会遇到问题。

$"new TaskSolution().Calculate({input})"的计算结果为"new TaskSolution().Calculate(System.Int32[])",为无效代码。input将被视为字符串,而不是作为实际的数组传递。

最新更新