本文整理汇总了C#中ScriptEngine.Process方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.Process方法的具体用法?C# ScriptEngine.Process怎么用?C# ScriptEngine.Process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.Process方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TriggerFunction
public void TriggerFunction()
{
var script = new ScriptEngine();
script.AddAction<int>("log1", message =>
{
Assert.AreEqual(10, message);
});
script.AddAction<string>("log2", message =>
{
Assert.Fail();
});
var code = new StringBuilder();
code.AppendLine("event drop(item)");
code.AppendLine(" log1(item)");
code.AppendLine("event foo");
code.AppendLine(" log2('Goodbye World!')");
script.Process(code.ToString());
script.Trigger("drop", 10);
}
示例2: trigger_Click
private void trigger_Click(object sender, RoutedEventArgs e)
{
var engine = new ScriptEngine();
engine.Exception(err =>
{
error.Text = err.Message;
});
engine.AddAction<string>("log", ActionMessage);
engine.Process(code.Text);
output.Text = "";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
engine.Trigger("name", 10);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
time.Text = String.Format("({0:00}.{1:00})",
ts.Seconds,
ts.Milliseconds / 10);
}
示例3: TriggerBasic
public void TriggerBasic()
{
var script = new ScriptEngine();
script.AddAction<string>("log1", message =>
{
Assert.AreEqual("Hello World 1!", message);
});
script.AddAction<string>("log2", message =>
{
Assert.AreEqual("Hello World 2!", message);
});
script.AddAction<string>("log", message =>
{
Assert.Fail();
});
var code = new StringBuilder();
code.AppendLine("event action");
code.AppendLine(" log1('Hello World 1!')");
code.AppendLine(" log2('Hello World 2!')");
code.AppendLine("event foo");
code.AppendLine(" log('Goodbye World!')");
script.Process(code.ToString());
script.Trigger("action");
}