("1 + 2"); 评估一个C#表达式(强类型)(Evaluate a C# expression(strongly-typed)) int result = await CSharpScript.EvaluateAsync var result = await CSharpScript.EvaluateAsync("Directory.GetCurrentDirectory()"), ::: 创建和构建一个C#脚本,并多次执行(Create&build a C# script and execute it multiple times) var script = CSharpScript.Create var script = CSharpScript.Create<int>("X*Y", globalsType: typeof(Globals)); ScriptRunner<int> runner variable.Value} of type {variable.Type}"); 将代码片段链接成一个脚本(Chain code snippets to form a script) var script = CSharpScript
假如我们执行如下代码 Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.RunAsync("var i = 3;"); var result = Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.RunAsync("i * 2"); 得到的并不是我们想要的结果6,而是一个异常: ? 究其原因,是因为CSharpScript.RunAsync 函数每次都是在一个单独的上下文中执行的,并不会和前面的语句产生关联。 如果我们要在CSharpScript.Create()函数创建一个脚本,通过函数ContinueWith 组成一个完整的脚本运行。 正确方式如下: var s0 = CSharpScript.Create("int x = 1;"); var s1 = s0.ContinueWith("int y = 2;")
Program).Assembly) .AddImports("Scripting"); //Success await CSharpScript class Program { static async Task Main(string[] args) { //Fail await CSharpScript
option; } public static object Execute(string code) { var script = CSharpScript.Create
Assembly) // mscorlib/System.Runtime .AddImports("System"); // 免写 using await CSharpScript.EvaluateAsync , opts); // 预热 for (int i = 0; i < 10; i++) { var sw = Stopwatch.StartNew(); var d = await CSharpScript.EvaluateAsync
-diagram 简单使用,自定义一个text模块的代码如下: Code = @"using System; namespace AIStudio.Wpf.CSharpScript { public assembly.GetTypes().FirstOrDefault(p => p.FullName.StartsWith("AIStudio.Wpf")); //assembly.GetType("AIStudio.Wpf.CSharpScript.Write
codescript = formatter.Replace("$", "\"" + val + "\""); 88 var fval = CSharpScript.EvaluateAsync