{"id":321743,"date":"2021-04-20T09:00:23","date_gmt":"2021-04-20T09:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=321743"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=321743","title":{"rendered":"\u0421\u043a\u0440\u0438\u043f\u0442\u0438\u043d\u0433 \u0432 C# \u0438\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432 runtime"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043d\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u0432 C# \u0435\u0441\u0442\u044c \u0448\u0442\u0443\u043a\u0430 \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0438 eval \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f Roslyn API, \u043c\u043e\u0436\u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c C# \u043a\u043e\u0434. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/Fantoom\/CSharpREPL\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/a> <a href=\"https:\/\/ru.wikipedia.org\/wiki\/REPL\" rel=\"noopener noreferrer nofollow\">REPL<\/a>-\u0430 \u0434\u043b\u044f C#.<\/p>\n<p>\u0412\u043f\u0435\u0440\u0432\u044b\u0435 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0448\u0442\u0443\u043a\u043e\u0439, \u043a\u0430\u043a REPL, \u044f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0442\u0435\u0440\u0435\u0431\u0438\u043b \u043f\u0438\u0442\u043e\u043d\u0430. \u0412 \u043c\u0438\u0440\u0435 .NET \u0435\u0441\u0442\u044c \u043f\u043e\u0445\u043e\u0436\u0430\u044f \u0432\u0435\u0449\u044c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c C# Interactive (CSI). \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043d\u043e \u0443 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u2014 \u043e\u043d\u0430 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Visual Studio, \u0442\u0430\u043a \u0447\u0442\u043e \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 VS, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0430 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0435 \u0431\u0435\u0437 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 VS, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e \u043b\u0435\u0437\u0442\u044c \u0432 \u0435\u0435 \u043d\u0435\u0434\u0440\u0430 (\u0430 \u0442\u043e\u0447\u043d\u0435\u0435, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\Tools\\VsDevCmd.bat), \u0447\u0442\u043e \u0442\u0430\u043a \u0441\u0435\u0431\u0435.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u043a\u0430\u043a <a href=\"https:\/\/github.com\/filipw\/dotnet-script\" rel=\"noopener noreferrer nofollow\">dotnet-script<\/a> \u0438 <a href=\"https:\/\/www.cs-script.net\/\" rel=\"noopener noreferrer nofollow\">cs-script<\/a> (\u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a>), \u043d\u043e \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u2014 \u043e\u043d\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0435 \u043c\u043d\u043e\u0439. \u0412\u043e\u0442 \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043c\u044b\u0441\u043b\u044c, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0440\u044f\u0432\u044b\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043d\u043e \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0444\u0438\u0447\u0430\u043c\u0438! (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u043a\u043e\u0440\u044f\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442). \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u0434\u043e\u043b\u0433\u0438\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432, \u043c\u043e\u0439 \u0432\u0437\u043e\u0440 \u0443\u043f\u0430\u043b \u043d\u0430 \u0441\u0438\u0435 \u0447\u0443\u0434\u043e: <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a>. \u0418\u0437 \u043f\u043b\u044e\u0441\u043e\u0432 \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 API, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0431\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 namespace-\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0433\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c using <\/p>\n<pre><code class=\"cs\">using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting;<\/code><\/pre>\n<p>CSharpScript &#8212; \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 3 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p>Create &#8212; \u0441\u043e\u0437\u0434\u0430\u0435\u0442 Script \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>RunAsync &#8212; \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ScriptState<\/p>\n<\/li>\n<li>\n<p>EvaluateAsync &#8212; \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>CSharpScript.Create \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<pre><code class=\"cs\">var script = CSharpScript.Create(\"System.Console.WriteLine(\\\"Hello from script\\\")\"); script.Compile(); await script.RunAsync();<\/code><\/pre>\n<p>E\u0441\u043b\u0438 \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c Compile(), \u0442\u043e \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435.<\/p>\n<p> \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c ScriptOptions, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c namespace-\u044b \u0438 reference-\u044b (\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0438 using static).<\/p>\n<pre><code class=\"cs\">  var options = ScriptOptions.Default             .AddImports(\"System\", \"System.IO\", \"System.Collections.Generic\",                 \"System.Console\", \"System.Diagnostics\", \"System.Dynamic\",                 \"System.Linq\", \"System.Text\",                 \"System.Threading.Tasks\")             .AddReferences(\"System\", \"System.Core\", \"Microsoft.CSharp\");   CSharpScript.Create(\"Console.WriteLine(\\\"Hello from script\\\")\", options);<\/code><\/pre>\n<p>\u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 ScriptOptions \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 namespace-\u044b. \u042d\u0442\u0430\u043a\u0438\u0439 whitelist, \u043a\u0430\u043a \u044f \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0441\u044f.<\/p>\n<p>CSharpScript.RunAsync \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ScriptState, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u0432 ContinueWithAsync, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u043a\u043e\u0434 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 ScriptState. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043e\u0431\u0440\u0430\u0442\u0438\u0432\u0448\u0438\u0441\u044c \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 Script. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e ReturnValue.<\/p>\n<pre><code class=\"cs\">ScriptState state = await CSharpScript.RunAsync(\"int x = 5;\"); state = await state.ContinueWithAsync&lt;int&gt;(\"x + 1\"); Console.WriteLine(state.ReturnValue); \/\/ 6<\/code><\/pre>\n<p>\u0423 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 state \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 exception<\/p>\n<pre><code class=\"cs\">foreach(var variable in state.Variables) { \tConsole.WriteLine($\"{variable.Name} - {variable.Value}\"); }<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e CSharpScript.Create \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442 \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435<\/p>\n<pre><code class=\"cs\">var script = CSharpScript.Create&lt;Func&lt;int,int&gt;&gt;(\"x =&gt; x+1\"); Console.WriteLine(await script.CreateDelegate().Invoke(1)); \/\/ 2<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a \u0436\u0435, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f CSharpScript.EvaluateAsync (\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u0448\u0435) <\/p>\n<pre><code class=\"cs\">var deleg = await CSharpScript.EvaluateAsync&lt;Func&lt;int, int&gt;&gt;(\"x =&gt; x * 2\"); Console.WriteLine(deleg(5)); \/\/ 10<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u043c\u043e\u0439 \u0441\u043a\u0443\u0434\u043d\u044b\u0439 \u0443\u043c \u043d\u0435 \u0441\u043c\u043e\u0433 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u044e\u0437\u043a\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u043e \u044f \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0442\u0430\u043a\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u0431\u044b\u043b\u0430 \u043d\u0443\u0436\u043d\u0430)<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0442\u0435\u0441\u0442\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fb7\/3d3\/69b\/fb73d369b8d1c3bb4cf0a1ec3c755eb5.png\" width=\"746\" height=\"211\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0447\u0435\u043d\u044c \u0442\u043e\u0447\u043d\u044b, \u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0421 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u043f\u043e <a href=\"https:\/\/pastebin.com\/gpDRhirB\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a>, \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0443\u0442\u043a\u0430, \u0434\u043b\u044f runtime \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f C# \u043a\u043e\u0434\u0430. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0441\u0432\u043e\u0435\u043c \u0434\u0432\u0438\u0436\u043a\u0435, \u0438\u043b\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0431\u0435\u0437 \u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f .net \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0435\u0433\u043e \u0441\u0431\u043e\u0440\u043a\u0438.<\/p>\n<p>\u0422\u043e\u043f 5 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0440\u0435\u043f \u0432 github, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aa0\/629\/c11\/aa0629c11c3dfc3fdcdd2e927fd5e810.png\" width=\"789\" height=\"482\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c \u0432\u043d\u0438\u0437\u0443:<\/p>\n<p><a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/wiki\/Scripting-API-Samples.md\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/wiki\/Scripting-API-Samples.md<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/dotnet\/roslyn\/tree\/a7319e2bc8cac34c34527031e6204d383d29d4ab\/src\/Scripting\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dotnet\/roslyn\/tree\/a7319e2bc8cac34c34527031e6204d383d29d4ab\/src\/Scripting<\/a><\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043a\u0443\u0447\u043d\u043e\u0439, \u0438 \u044f \u0441\u043c\u043e\u0433 \u043a\u0430\u043a-\u0442\u043e \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0447\u044c.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0432\u0430\u043c \u0434\u043d\u044f!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/553310\/\"> https:\/\/habr.com\/ru\/post\/553310\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043d\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u0432 C# \u0435\u0441\u0442\u044c \u0448\u0442\u0443\u043a\u0430 \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0438 eval \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f Roslyn API, \u043c\u043e\u0436\u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c C# \u043a\u043e\u0434. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/Fantoom\/CSharpREPL\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/a> <a href=\"https:\/\/ru.wikipedia.org\/wiki\/REPL\" rel=\"noopener noreferrer nofollow\">REPL<\/a>-\u0430 \u0434\u043b\u044f C#.<\/p>\n<p>\u0412\u043f\u0435\u0440\u0432\u044b\u0435 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0448\u0442\u0443\u043a\u043e\u0439, \u043a\u0430\u043a REPL, \u044f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0442\u0435\u0440\u0435\u0431\u0438\u043b \u043f\u0438\u0442\u043e\u043d\u0430. \u0412 \u043c\u0438\u0440\u0435 .NET \u0435\u0441\u0442\u044c \u043f\u043e\u0445\u043e\u0436\u0430\u044f \u0432\u0435\u0449\u044c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c C# Interactive (CSI). \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043d\u043e \u0443 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u2014 \u043e\u043d\u0430 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 Visual Studio, \u0442\u0430\u043a \u0447\u0442\u043e \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 VS, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0430 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0435 \u0431\u0435\u0437 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 VS, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e \u043b\u0435\u0437\u0442\u044c \u0432 \u0435\u0435 \u043d\u0435\u0434\u0440\u0430 (\u0430 \u0442\u043e\u0447\u043d\u0435\u0435, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\Tools\\VsDevCmd.bat), \u0447\u0442\u043e \u0442\u0430\u043a \u0441\u0435\u0431\u0435.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u043a\u0430\u043a <a href=\"https:\/\/github.com\/filipw\/dotnet-script\" rel=\"noopener noreferrer nofollow\">dotnet-script<\/a> \u0438 <a href=\"https:\/\/www.cs-script.net\/\" rel=\"noopener noreferrer nofollow\">cs-script<\/a> (\u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a>), \u043d\u043e \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u2014 \u043e\u043d\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0435 \u043c\u043d\u043e\u0439. \u0412\u043e\u0442 \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043c\u044b\u0441\u043b\u044c, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0440\u044f\u0432\u044b\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043d\u043e \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0444\u0438\u0447\u0430\u043c\u0438! (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u043a\u043e\u0440\u044f\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442). \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u0434\u043e\u043b\u0433\u0438\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432, \u043c\u043e\u0439 \u0432\u0437\u043e\u0440 \u0443\u043f\u0430\u043b \u043d\u0430 \u0441\u0438\u0435 \u0447\u0443\u0434\u043e: <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a>. \u0418\u0437 \u043f\u043b\u044e\u0441\u043e\u0432 \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 API, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0431\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 namespace-\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0433\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c using <\/p>\n<pre><code class=\"cs\">using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting;<\/code><\/pre>\n<p>CSharpScript &#8212; \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 3 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p>Create &#8212; \u0441\u043e\u0437\u0434\u0430\u0435\u0442 Script \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>RunAsync &#8212; \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ScriptState<\/p>\n<\/li>\n<li>\n<p>EvaluateAsync &#8212; \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>CSharpScript.Create \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<pre><code class=\"cs\">var script = CSharpScript.Create(\"System.Console.WriteLine(\\\"Hello from script\\\")\"); script.Compile(); await script.RunAsync();<\/code><\/pre>\n<p>E\u0441\u043b\u0438 \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c Compile(), \u0442\u043e \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435.<\/p>\n<p> \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c ScriptOptions, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c namespace-\u044b \u0438 reference-\u044b (\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0438 using static).<\/p>\n<pre><code class=\"cs\">  var options = ScriptOptions.Default             .AddImports(\"System\", \"System.IO\", \"System.Collections.Generic\",                 \"System.Console\", \"System.Diagnostics\", \"System.Dynamic\",                 \"System.Linq\", \"System.Text\",                 \"System.Threading.Tasks\")             .AddReferences(\"System\", \"System.Core\", \"Microsoft.CSharp\");   CSharpScript.Create(\"Console.WriteLine(\\\"Hello from script\\\")\", options);<\/code><\/pre>\n<p>\u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 ScriptOptions \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 namespace-\u044b. \u042d\u0442\u0430\u043a\u0438\u0439 whitelist, \u043a\u0430\u043a \u044f \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0441\u044f.<\/p>\n<p>CSharpScript.RunAsync \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ScriptState, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u0432 ContinueWithAsync, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u043a\u043e\u0434 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 ScriptState. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043e\u0431\u0440\u0430\u0442\u0438\u0432\u0448\u0438\u0441\u044c \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 Script. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e ReturnValue.<\/p>\n<pre><code class=\"cs\">ScriptState state = await CSharpScript.RunAsync(\"int x = 5;\"); state = await state.ContinueWithAsync&lt;int&gt;(\"x + 1\"); Console.WriteLine(state.ReturnValue); \/\/ 6<\/code><\/pre>\n<p>\u0423 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 state \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 exception<\/p>\n<pre><code class=\"cs\">foreach(var variable in state.Variables) { \tConsole.WriteLine($\"{variable.Name} - {variable.Value}\"); }<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e CSharpScript.Create \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442 \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435<\/p>\n<pre><code class=\"cs\">var script = CSharpScript.Create&lt;Func&lt;int,int&gt;&gt;(\"x =&gt; x+1\"); Console.WriteLine(await script.CreateDelegate().Invoke(1)); \/\/ 2<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a \u0436\u0435, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f CSharpScript.EvaluateAsync (\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u0448\u0435) <\/p>\n<pre><code class=\"cs\">var deleg = await CSharpScript.EvaluateAsync&lt;Func&lt;int, int&gt;&gt;(\"x =&gt; x * 2\"); Console.WriteLine(deleg(5)); \/\/ 10<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u043c\u043e\u0439 \u0441\u043a\u0443\u0434\u043d\u044b\u0439 \u0443\u043c \u043d\u0435 \u0441\u043c\u043e\u0433 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u044e\u0437\u043a\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u043e \u044f \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0442\u0430\u043a\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u0431\u044b\u043b\u0430 \u043d\u0443\u0436\u043d\u0430)<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0442\u0435\u0441\u0442\u044b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0447\u0435\u043d\u044c \u0442\u043e\u0447\u043d\u044b, \u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0421 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u043f\u043e <a href=\"https:\/\/pastebin.com\/gpDRhirB\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.CodeAnalysis.CSharp.Scripting\" rel=\"noopener noreferrer nofollow\">Microsoft.CodeAnalysis.CSharp.Scripting<\/a>, \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0443\u0442\u043a\u0430, \u0434\u043b\u044f runtime \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f C# \u043a\u043e\u0434\u0430. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0441\u0432\u043e\u0435\u043c \u0434\u0432\u0438\u0436\u043a\u0435, \u0438\u043b\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0431\u0435\u0437 \u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f .net \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0435\u0433\u043e \u0441\u0431\u043e\u0440\u043a\u0438.<\/p>\n<p>\u0422\u043e\u043f 5 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0440\u0435\u043f \u0432 github, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c \u0432\u043d\u0438\u0437\u0443:<\/p>\n<p><a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/wiki\/Scripting-API-Samples.md\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/wiki\/Scripting-API-Samples.md<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/dotnet\/roslyn\/tree\/a7319e2bc8cac34c34527031e6204d383d29d4ab\/src\/Scripting\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dotnet\/roslyn\/tree\/a7319e2bc8cac34c34527031e6204d383d29d4ab\/src\/Scripting<\/a><\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043a\u0443\u0447\u043d\u043e\u0439, \u0438 \u044f \u0441\u043c\u043e\u0433 \u043a\u0430\u043a-\u0442\u043e \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0447\u044c.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0432\u0430\u043c \u0434\u043d\u044f!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/553310\/\"> https:\/\/habr.com\/ru\/post\/553310\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-321743","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321743"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321743\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}