本文整理汇总了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());
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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!')");
}
示例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");
}
示例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());
}
示例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());
}
示例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);
}