我试图通过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)运行类似的方法时,它将成功运行。但我在使用数组时遇到了问题。
发布于 2022-12-04 17:48:15
$"new TaskSolution().Calculate({input})"的计算结果为"new TaskSolution().Calculate(System.Int32[])",这是无效代码。input将被视为字符串,而不是作为实际数组传递。
https://stackoverflow.com/questions/74678356
复制相似问题