本文整理汇总了C#中ScriptEngine.Exception方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.Exception方法的具体用法?C# ScriptEngine.Exception怎么用?C# ScriptEngine.Exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.Exception方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArithmeticIntegerAddString
public void ArithmeticIntegerAddString()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.Fail(e.Message);
});
Assert.AreEqual("40text", script.Evaluate<string>("40 + 'text'"));
}
示例2: ArithmeticIntegerDivideInterger
public void ArithmeticIntegerDivideInterger()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.Fail(e.Message);
});
Assert.AreEqual(20.0, script.Evaluate<double>("40 / 2"));
}
示例3: ArithmeticIntegerAddInteger
public void ArithmeticIntegerAddInteger()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.Fail(e.Message);
});
Assert.AreEqual(42, script.Evaluate<int>("40 + 2"));
}
示例4: ArithmeticIntegerAddListString
public void ArithmeticIntegerAddListString()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.Fail(e.Message);
});
Assert.AreEqual("40hello,world,!", script.Evaluate<string>("40 + ['hello', 'world', '!']"));
}
示例5: VariableStringToInt
public void VariableStringToInt()
{
var script = new ScriptEngine();
var code = new StringBuilder();
script.Exception(error =>
{
Assert.AreEqual("String 'foo' set to Integer on Line 1 Col 13", error.Message);
});
code.AppendLine("string foo = 4");
code.AppendLine("foo");
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: DebugLogSetList
public void DebugLogSetList()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.Fail(e.Message);
});
var code = new StringBuilder();
code.AppendLine("string[] foo = ['Hello', 'World!']");
code.AppendLine("foo");
var value = script.Evaluate<List<string>>(code.ToString());
Assert.AreEqual(value[0], "Hello");
}
示例8: DebugLogArray
public void DebugLogArray()
{
var script = new ScriptEngine();
var debugClass = script.AddClass("debug");
debugClass.AddAction<List<string>>("log", message =>
{
Assert.AreEqual("Hello World!", message[0]);
});
script.Exception(e =>
{
Assert.Fail(e.Message);
});
script.Execute("debug.log(['Hello World!'])");
}
示例9: 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());
}
示例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);
}
示例11: ArithmeticIntegerMinusDouble
public void ArithmeticIntegerMinusDouble()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.Fail(e.Message);
});
Assert.AreEqual(38.0, script.Evaluate<double>("40 - 2.0"));
}
示例12: ArithmeticIntegerDivideString
public void ArithmeticIntegerDivideString()
{
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.AreEqual("Unable to cast value 'text' from 'String' to 'Double' on Line 1 Col 5", e.Message);
});
script.Execute("40 / 'text'");
}
示例13: ListStringNestedAndRead
public void ListStringNestedAndRead()
{
// Nested arrays are not supported.
var script = new ScriptEngine();
script.Exception(e =>
{
Assert.AreEqual("Invalid data type 'ListString' in 'String' list near Line 1 Col 36", e.Message);
});
var code = new StringBuilder();
code.AppendLine("string[] foo = [['Hello', 'Again'], 'World!']");
code.AppendLine("foo[0][0]");
var value = script.Evaluate<string>(code.ToString());
Assert.AreNotEqual(value, "Hello");
}