本文整理汇总了C#中Interpreter.Eval方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.Eval方法的具体用法?C# Interpreter.Eval怎么用?C# Interpreter.Eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter.Eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_use_overloaded_operators_on_class
public void Can_use_overloaded_operators_on_class()
{
var target = new Interpreter();
var x = new ClassWithOverloadedBinaryOperators(3);
target.SetVariable("x", x);
string y = "5";
Assert.IsFalse(x == y);
Assert.IsFalse(target.Eval<bool>("x == y", new Parameter("y", y)));
y = "3";
Assert.IsTrue(x == y);
Assert.IsTrue(target.Eval<bool>("x == y", new Parameter("y", y)));
Assert.IsFalse(target.Eval<bool>("x == \"4\""));
Assert.IsTrue(target.Eval<bool>("x == \"3\""));
Assert.IsTrue(!x == "-3");
Assert.IsTrue(target.Eval<bool>("!x == \"-3\""));
var z = new ClassWithOverloadedBinaryOperators(10);
Assert.IsTrue((x + z) == "13");
Assert.IsTrue(target.Eval<bool>("(x + z) == \"13\"", new Parameter("z", z)));
}
示例2: True_False_Literals
public void True_False_Literals()
{
var target = new Interpreter();
Assert.IsTrue((bool)target.Eval("true"));
Assert.IsFalse((bool)target.Eval("false"));
}
示例3: Convert_Class
public void Convert_Class()
{
var target = new Interpreter();
Assert.AreEqual(Convert.ToString(3), target.Eval("Convert.ToString(3)"));
Assert.AreEqual(Convert.ToInt16("23"), target.Eval("Convert.ToInt16(\"23\")"));
}
示例4: New_And_Member_Access
public void New_And_Member_Access()
{
var target = new Interpreter();
Assert.AreEqual(new DateTime(2015, 1, 24).Month, target.Eval("new DateTime(2015, 1, 24).Month"));
Assert.AreEqual(new DateTime(2015, 1, 24).Month + 34, target.Eval("new DateTime( 2015, 1, 24).Month + 34"));
}
示例5: Alphabetic_Literals
public void Alphabetic_Literals()
{
var target = new Interpreter();
Assert.AreEqual("ciao", target.Eval("\"ciao\""));
Assert.AreEqual('c', target.Eval("'c'"));
}
示例6: Static_Methods_of_Base_Types
public void Static_Methods_of_Base_Types()
{
var target = new Interpreter();
Assert.AreEqual(TimeSpan.FromMilliseconds(2000.49), target.Eval("TimeSpan.FromMilliseconds(2000.49)"));
Assert.AreEqual(DateTime.DaysInMonth(2094, 11), target.Eval("DateTime.DaysInMonth(2094, 11)"));
}
示例7: If_Operators
public void If_Operators()
{
var target = new Interpreter();
Assert.AreEqual(10 > 3 ? "yes" : "no", target.Eval("10 > 3 ? \"yes\" : \"no\""));
Assert.AreEqual(10 < 3 ? "yes" : "no", target.Eval("10 < 3 ? \"yes\" : \"no\""));
}
示例8: Numeric_Operators_Priority
public void Numeric_Operators_Priority()
{
var target = new Interpreter();
Assert.AreEqual(8 / 2 + 2, target.Eval("8 / 2 + 2"));
Assert.AreEqual(8 + 2 / 2, target.Eval("8 + 2 / 2"));
}
示例9: New_Of_Base_Type
public void New_Of_Base_Type()
{
var target = new Interpreter();
Assert.AreEqual(new DateTime(2015, 1, 24), target.Eval("new DateTime(2015, 1, 24)"));
Assert.AreEqual(new string('a', 10), target.Eval("new string('a', 10)"));
}
示例10: Math_Class
public void Math_Class()
{
var target = new Interpreter();
Assert.AreEqual(Math.Pow(3, 4), target.Eval("Math.Pow(3, 4)"));
Assert.AreEqual(Math.Sin(30.234), target.Eval("Math.Sin(30.234)"));
}
示例11: Variables_can_be_case_insensitive
public void Variables_can_be_case_insensitive()
{
var target = new Interpreter(InterpreterOptions.DefaultCaseInsensitive)
.SetVariable("x", 23);
Assert.AreEqual(23, target.Eval("x"));
Assert.AreEqual(23, target.Eval("X"));
}
示例12: Type_Related_Static_Methods
public void Type_Related_Static_Methods()
{
var target = new Interpreter()
.Reference(typeof(Type));
Assert.AreEqual(Type.GetType("System.Globalization.CultureInfo"), target.Eval("Type.GetType(\"System.Globalization.CultureInfo\")"));
Assert.AreEqual(DateTime.Now.GetType(), target.Eval("DateTime.Now.GetType()"));
}
示例13: Multiplicative_Operators
public void Multiplicative_Operators()
{
var target = new Interpreter();
Assert.AreEqual(2 * 4, target.Eval("2 * 4"));
Assert.AreEqual(8 / 2, target.Eval("8 / 2"));
Assert.AreEqual(7 % 3, target.Eval("7 % 3"));
}
示例14: Unary_Operators
public void Unary_Operators()
{
var target = new Interpreter();
Assert.AreEqual(-45, target.Eval("-45"));
Assert.AreEqual(5, target.Eval("+5"));
Assert.AreEqual(false, target.Eval("!true"));
}
示例15: Additive_Operators
public void Additive_Operators()
{
var target = new Interpreter();
Assert.AreEqual(45 + 5, target.Eval("45 + 5"));
Assert.AreEqual(45 - 5, target.Eval("45 - 5"));
Assert.AreEqual(1.0 - 0.5, target.Eval("1.0 - 0.5"));
}