1. 安装nuget package
2.使用Roslyn 动态执行
var engine = newRoslyn.Scripting.CSharp.ScriptEngine(); engine.CreateSession().Execute ("System.Console.WriteLine(\"Hello , Roslyn .\");");
3.使用Roslyn 动态编译
var engine = newRoslyn.Scripting.CSharp.ScriptEngine(); var list = new List<string> {"abc", "bcd","acd"}; var excutable = engine.CreateSession(). CompileSubmission<Func<string,bool>> ("(m) =>{returnm.StartsWith(\"a\");}").Execute(); var startWitha = list. Where(excutable); foreach (var str in startWitha) { Console.WriteLine(str); }
时间: 2024-11-10 23:00:16