Выполнение кода с Roslyn - C#
Формулировка задачи:
Добрый день. Например:
Есть класс с названием Test:
Как мне выполнить строку:
с помощью Roslyn?
Заранее спасибо!
public static class Test
{
public static void PrintLine(string Text)
{
Console.WriteLine(Text);
}
}Test.PrintLine("Hello World");Решение задачи: «Выполнение кода с Roslyn»
textual
Листинг программы
static async void ScriptTest()
{
var globals = new Globals(new Test1(), new Test2());
var script = CSharpScript.Create("", globalsType: globals.GetType());
var method1 = script.ContinueWith("A.PrintLine1("Hello World");");
var method2 = script.ContinueWith("B.PrintLine2("Hello World");");
script.Compile();
await method1.RunAsync(globals);
await method2.RunAsync(globals);
}