动态执行c#代码

  1. Roslyn
    安装Microsoft.CodeAnalysis.CSharp.Scripting
    using Microsoft.CodeAnalysis.CSharp.Scripting;
    using Microsoft.CodeAnalysis.Scripting;
 string code = "int result = 1 + 2; Console.WriteLine(result);";

 var options = ScriptOptions.Default.WithImports("System");

 var script = CSharpScript.Create(code, options);

 script.RunAsync().Wait();

[参考]
https://blog.csdn.net/weixin_30802273/article/details/99274776

posted @ 2024-11-15 13:11  Hey,Coder!  阅读(3)  评论(0编辑  收藏  举报