本文整理汇总了C#中Script.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Script.Add方法的具体用法?C# Script.Add怎么用?C# Script.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Script
的用法示例。
在下文中一共展示了Script.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public Script Parse(string scriptString)
{
Script script = new Script();
CommandFactory factory = new CommandFactory();
scriptString = scriptString.Replace("\r\n", "\n");
string[] lines = scriptString.Trim().Split('\n');
script.Add(factory.CreateCommand(lines[0])); //first line is a special command to show form.
for(int i = 1; i < lines.Length; i++)
{
if(lines[i].Trim() == string.Empty)
{
script.Add(factory.CreateCommand());
}
else if(lines[i].Trim().StartsWith("'"))
{
script.Add(factory.CreateCommand());
}
else
{
//this requires exactly one space between tokens.. *sigh*
//don't want to split args or force quotes around strings with spaces..
string thisLine = lines[i];
int firstBreak = thisLine.IndexOf(" ");
int secondBreak = thisLine.IndexOf(" ", firstBreak + 1);
string control = thisLine.Substring(0, firstBreak);
string action = thisLine.Substring(firstBreak + 1, secondBreak - firstBreak - 1);
string args = thisLine.Substring(secondBreak + 1);
script.Add(factory.CreateCommand(control, action, args));
}
}
return script;
}
示例2: ScriptProducesStatements
public void ScriptProducesStatements()
{
var a = JS.Id("a");
Script script1 = new Script
{
JS.Var(a),
{
JS.For(a.AssignWith(3), a.IsGreaterThan(0), a.PreDecrement())
.Do(JS.Alert(a)),
JS.Return(a)
}
};
Assert.AreEqual(3, script1.Statements.Count);
Assert.AreEqual("var a;for(a=3;a>0;--a)alert(a);return a;", script1.ToString());
Script script2 = new Script();
script2.Add(script1);
Assert.AreEqual("var a;for(a=3;a>0;--a)alert(a);return a;", script2.ToString());
}
示例3: getSampleScript
private static Script getSampleScript(ScriptContext context)
{
Script script = new Script();
script.Id = "WAIT";
script.VersionInfo.Title = "WAIT";
script.VersionInfo.Value = "(Generated sample script)";
script.EngineVersion = context.CoreVersion.ToString();
script.Parameters.Add(
new CommandLineParameter { Default = "2000", Value = "Number of seconds to wait", Description = "seconds", Switch = "seconds", Count = CommandLineValueCount.Single }
);
script.Parameters.Add(
new CommandLineParameter { Default = "0", Value = "Display this message", Switch = "help", Synonyms = "?;helpme", Unspecified = "true" }
);
script.Add(new Code { Value = "Context.WriteLine(\"Hello, world!\");" });
script.Add(new Code { Value = "Context.WriteLine(\"This script will be waiting for {0} seconds.\",c[\"seconds\"]);" });
Timer timer = new Timer { OutTo = "execTime", Format = TimerFormat.TimeSpan };
timer.Add(new Sleep { Timeout = "${seconds}" });
script.AddTry(timer);
script.AddTry(new Print { Value="Execution took ${execTime}"});
script.AddTry(new Throw { Value = "Test error" });
script.AddTry(new Print { Value = "This will not be printed" });
script.AddCatch(new Print { Value = "Catched exception: ${=c.CurrentException.Message}" });
script.AddFinally(new Print { Value = "Clean up part" });
return script;
}
示例4: Sum
public Script Sum(Script A, Script B)
{
Script script = new Script();
script._arr.AddRange(A._arr);
script._arr.AddRange(B._arr);
script.Add(new SwfDotnet.Format.ActionScript.Action(10));
return script;
}