Code: Select all
static async Task Main(string[] args)
{
var variables = new Dictionary
{
{ "x", 10 },
{ "y", 20 },
{ "message", "Hello, Roslyn!" }
};
string script = @"
var result = x + y;
$""{message} Result: {result}"";
";
// Options de script
var options = ScriptOptions.Default.AddReferences(
typeof(object).Assembly
);
var globals = new Globals { Variables = variables };
try
{
var result = await CSharpScript.EvaluateAsync(
script,
options,
globals
);
Console.WriteLine(result);
Console.ReadLine();
}
catch (CompilationErrorException ex)
{
Console.WriteLine("Erreur de compilation :");
Console.WriteLine(string.Join(Environment.NewLine, ex.Diagnostics));
}
Console.ReadLine();
}
Code: Select all
Erreur de compilation :
(2,26): error CS0103: The name 'x' does not exist in the current context
(2,30): error CS0103: The name 'y' does not exist in the current context
(3,16): error CS0103: The name 'message' does not exist in the current context
(3,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Hinweis: Die im Skript verwendeten Variablen können jeden Typ haben, JOBJECT DataTables...