当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.AddAction方法代码示例

本文整理汇总了C#中ScriptEngine.AddAction方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.AddAction方法的具体用法?C# ScriptEngine.AddAction怎么用?C# ScriptEngine.AddAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.AddAction方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteOverload

 public void ExecuteOverload()
 {
     var script = new ScriptEngine();
     script.AddAction<string>("log", message =>
     {
         Assert.AreEqual("Hello World!", message);
     });
     script.AddAction<string, string>("log", (message1, message2) =>
     {
         Assert.AreEqual("Hello World!", message1 + " " + message2);
     });
     var code = new StringBuilder();
     code.AppendLine("log('Hello World!')"); // Should run log, pass { indent: 1 }
     code.AppendLine("log('Hello', 'World!')"); // Should run log, pass { indent: 1 }
     script.Execute(code.ToString());
 }
开发者ID:Templarian,项目名称:Script,代码行数:16,代码来源:ExecuteOverload.cs

示例2: 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);
 }
开发者ID:Templarian,项目名称:Script,代码行数:19,代码来源:Trigger.cs

示例3: ConditionBoolTrue

 public void ConditionBoolTrue()
 {
     var script = new ScriptEngine();
     script.AddAction<string>("log", message =>
     {
         Assert.AreEqual("Hello World!", message);
     });
     var code = new StringBuilder();
     code.AppendLine("if (true)"); // Basic if statment
     code.AppendLine("    log('Hello World!')"); // Should run log, pass { indent: 1 }
     script.Execute(code.ToString());
 }
开发者ID:Templarian,项目名称:Script,代码行数:12,代码来源:Condition.cs

示例4: ConditionBoolFalse

 public void ConditionBoolFalse()
 {
     var script = new ScriptEngine();
     script.AddAction<string>("log", message =>
     {
         Assert.Fail("This should never be called.");
     });
     var code = new StringBuilder();
     code.AppendLine("if (false)"); // Basic if statment
     code.AppendLine("    log('Hello World!')"); // Should run log, pass { indent: 1 }
     script.Execute(code.ToString());
 }
开发者ID:Templarian,项目名称:Script,代码行数:12,代码来源:Condition.cs

示例5: ConditionBoolTrue

 public void ConditionBoolTrue()
 {
     var script = new ScriptEngine();
     script.AddAction<string>("log", message =>
     {
         Assert.IsTrue(message == "test1" || message == "test2");
     });
     var code = new StringBuilder();
     code.AppendLine("for (var i in ['test1', 'test2'])"); // Basic if statment
     code.AppendLine("    log(i)"); // Should run log, pass { indent: 1 }
     script.Execute(code.ToString());
 }
开发者ID:Templarian,项目名称:Script,代码行数:12,代码来源:ForLoop.cs

示例6: FunctionInvalidArguments

 public void FunctionInvalidArguments()
 {
     var script = new ScriptEngine();
     script.AddAction<string>("log", message =>
     {
         Assert.Fail();
     });
     script.Exception(e =>
     {
         Assert.AreEqual("Unexpected string on Line 1 Col 14", e.Message);
     });
     script.Execute("log('Missing' 'Comma!')");
 }
开发者ID:Templarian,项目名称:Script,代码行数:13,代码来源:Function.cs

示例7: TriggerUndefined

 public void TriggerUndefined()
 {
     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("test");
 }
开发者ID:Templarian,项目名称:Script,代码行数:24,代码来源:Trigger.cs

示例8: ConditionBoolFalseOrFalse

 public void ConditionBoolFalseOrFalse()
 {
     var script = new ScriptEngine();
     script.Exception(ExceptionHandler);
     script.AddCondition<string>("foo", message =>
     {
         return "bar" == message;
     });
     script.AddAction<string>("log", message =>
     {
         Assert.Fail("This should never be called.");
     });
     var code = new StringBuilder();
     code.AppendLine("if (foo('fail1') and foo('fail2'))"); // Basic if statment
     code.AppendLine("    log('Hello World!')"); // Should run log, pass { indent: 1 }
     script.Execute(code.ToString());
 }
开发者ID:Templarian,项目名称:Script,代码行数:17,代码来源:Condition.cs

示例9: ConditionIfElseBoolTrue

 public void ConditionIfElseBoolTrue()
 {
     var script = new ScriptEngine();
     script.AddCondition<string>("foo", message =>
     {
         return "bar" == message;
     });
     script.AddAction<string>("log", message =>
     {
         Assert.AreEqual("Hello World!", message);
     });
     var code = new StringBuilder();
     code.AppendLine("if (foo('bar'))"); // Basic if statment
     code.AppendLine("    log('Hello World!')");
     code.AppendLine("else if (foo('blarg'))");
     code.AppendLine("    log('Goodbye World!')");
     script.Execute(code.ToString());
 }
开发者ID:Templarian,项目名称:Script,代码行数:18,代码来源:ConditionIfElse.cs

示例10: button_Click

 private void button_Click(object sender, RoutedEventArgs e)
 {
     var engine = new ScriptEngine();
     engine.Exception(err =>
     {
         error.Text = err.Message;
     });
     engine.AddAction<string>("log", ActionMessage);
     Stopwatch stopWatch = new Stopwatch();
     stopWatch.Start();
     output.Text = engine.Evaluate<string>(code.Text);
     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);
 }
开发者ID:Templarian,项目名称:Script,代码行数:18,代码来源:MainPage.xaml.cs


注:本文中的ScriptEngine.AddAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。