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


C# Interpreter.Eval方法代码示例

本文整理汇总了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)));
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:25,代码来源:OperatorsTest.cs

示例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"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:7,代码来源:LiteralsTest.cs

示例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\")"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:7,代码来源:StaticTest.cs

示例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"));
        }
开发者ID:kornarakis,项目名称:DynamicExpresso,代码行数:7,代码来源:ConstructorTest.cs

示例5: Alphabetic_Literals

        public void Alphabetic_Literals()
        {
            var target = new Interpreter();

            Assert.AreEqual("ciao", target.Eval("\"ciao\""));
            Assert.AreEqual('c', target.Eval("'c'"));
        }
开发者ID:nishannnb,项目名称:DynamicExpresso,代码行数:7,代码来源:LiteralsTest.cs

示例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)"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:7,代码来源:StaticTest.cs

示例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\""));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:7,代码来源:OperatorsTest.cs

示例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"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:7,代码来源:OperatorsTest.cs

示例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)"));
        }
开发者ID:kornarakis,项目名称:DynamicExpresso,代码行数:7,代码来源:ConstructorTest.cs

示例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)"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:7,代码来源:StaticTest.cs

示例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"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:8,代码来源:VariablesTest.cs

示例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()"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:8,代码来源:StaticTest.cs

示例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"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:8,代码来源:OperatorsTest.cs

示例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"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:8,代码来源:OperatorsTest.cs

示例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"));
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:8,代码来源:OperatorsTest.cs


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