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


C# Interpreter.Parse方法代码示例

本文整理汇总了C#中Interpreter.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.Parse方法的具体用法?C# Interpreter.Parse怎么用?C# Interpreter.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interpreter的用法示例。


在下文中一共展示了Interpreter.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: If_no_expression_type_is_specified_the_return_type_is_inferred

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

            Assert.AreEqual(typeof(string), target.Parse("\"ciao\"").ReturnType);
            Assert.AreEqual(typeof(int), target.Parse("45").ReturnType);
            Assert.AreEqual(typeof(double), target.Parse("45.4").ReturnType);
            Assert.AreEqual(typeof(object), target.Parse("null").ReturnType);
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:9,代码来源:ExpressionTypeTest.cs

示例2: CanInterpret

        public void CanInterpret()
        {
            Interpreter interpreter = new Interpreter();
            var commands = interpreter.Parse("PRESS A,B,C").ToList();
            Assert.AreEqual(1, commands.Count);
            var result = commands.First();
            Assert.AreEqual("PRESS", result.CommandType);
            Assert.AreEqual(3, result.Parameters.Count);

            Assert.AreEqual(0, interpreter.Parse("").Count());
            Assert.AreEqual(0, interpreter.Parse(null as string).Count());
        }
开发者ID:NicolasDorier,项目名称:GestSpace,代码行数:12,代码来源:UnitTest1.cs

示例3: Can_convert_a_null_expression_to_any_reference_type

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

            var lambda = target.Parse("null", typeof(string));
            Assert.AreEqual(typeof(string), lambda.ReturnType);
            Assert.IsNull(lambda.Invoke());

            lambda = target.Parse("null", typeof(TestReferenceType));
            Assert.AreEqual(typeof(TestReferenceType), lambda.ReturnType);
            Assert.IsNull(lambda.Invoke());
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:12,代码来源:ExpressionTypeTest.cs

示例4: A_nullable_type_can_be_a_value_or_null

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

            var lambda = target.Parse("null", typeof(int?));
            Assert.AreEqual(typeof(int?), lambda.ReturnType);
            Assert.IsNull(lambda.Invoke());

            lambda = target.Parse("4651", typeof(int?));
            Assert.AreEqual(typeof(int?), lambda.ReturnType);
            Assert.AreEqual(4651, lambda.Invoke());
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:12,代码来源:ExpressionTypeTest.cs

示例5: Can_convert_a_null_expression_to_any_nullable_type

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

            var lambda = target.Parse("null", typeof(int?));
            Assert.AreEqual(typeof(int?), lambda.ReturnType);
            Assert.IsNull(lambda.Invoke());

            lambda = target.Parse("null", typeof(DateTime?));
            Assert.AreEqual(typeof(DateTime?), lambda.ReturnType);
            Assert.IsNull(lambda.Invoke());
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:12,代码来源:ExpressionTypeTest.cs

示例6: Unary_Cast_Operator

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

			var x = 51.5;
			target.SetVariable("x", x);

			Assert.AreEqual((int)x, target.Eval("(int)x"));
			Assert.AreEqual(typeof(int), target.Parse("(int)x").ReturnType);
			Assert.AreEqual(typeof(object), target.Parse("(object)x").ReturnType);
			Assert.AreEqual((double)84 + 9 * 8, target.Eval("(double)84 + 9 *8"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:12,代码来源:OperatorsTest.cs

示例7: Empty_Null_Withespace_Expression

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

            Assert.AreEqual(null, target.Eval(""));
            Assert.AreEqual(typeof(void), target.Parse("").ReturnType);

            Assert.AreEqual(null, target.Eval(null));
            Assert.AreEqual(typeof(void), target.Parse(null).ReturnType);

            Assert.AreEqual(null, target.Eval("  \t\t\r\n  \t   "));
            Assert.AreEqual(typeof(void), target.Parse("  \t\t\r\n  \t   ").ReturnType);
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:13,代码来源:OtherTests.cs

示例8: As_Operator

        public void As_Operator()
        {
            object a = "string value";
            object b = 64;
            var target = new Interpreter()
                                                    .SetVariable("a", a, typeof(object))
                                                    .SetVariable("b", b, typeof(object));

            Assert.AreEqual(a as string, target.Eval("a as string"));
            Assert.AreEqual(typeof(string), target.Parse("a as string").ReturnType);
            Assert.AreEqual(b as string, target.Eval("b as string"));
            Assert.AreEqual(typeof(string), target.Parse("b as string").ReturnType);
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:13,代码来源:OperatorsTest.cs

示例9: CanInterpretTwoSentences

 public void CanInterpretTwoSentences()
 {
     Interpreter interpreter = new Interpreter();
     var commands = interpreter.Parse("PRESS A,\"B\",C\r\nPRESS A,B").ToList();
     Assert.AreEqual(2, commands.Count);
     Assert.AreEqual(2, commands[1].Parameters.Count);
 }
开发者ID:NicolasDorier,项目名称:GestSpace,代码行数:7,代码来源:UnitTest1.cs

示例10: Variables

		public void Variables()
		{
			var target = new Interpreter()
											.SetVariable("myk", 23);

			Assert.AreEqual(23, target.Eval("myk"));
			Assert.AreEqual(typeof(int), target.Parse("myk").ReturnType);
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:8,代码来源:VariablesTest.cs

示例11: Parse_To_a_Delegate_With_No_Parameters

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

            var func = target.Parse<Func<int>>("50");

            Assert.AreEqual(50, func());
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:8,代码来源:TypedDelegatesTest.cs

示例12: Parse_To_a_Delegate

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

            var lambda = target.Parse<Func<double, double, double>>("Math.Pow(x, y) + 5", "x", "y");

            Assert.AreEqual(Math.Pow(10, 2) + 5, lambda(10, 2));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:8,代码来源:TypedDelegatesTest.cs

示例13: Parse_To_a_Custom_Delegate

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

            var func = target.Parse<MyCustomDelegate>("x + y.Length");

            Assert.AreEqual(7, func(3, "ciao"));
            Assert.AreEqual(10, func(5, "mondo"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:9,代码来源:TypedDelegatesTest.cs

示例14: Null_Variables_With_Type_Specified

        public void Null_Variables_With_Type_Specified()
        {
            var target = new Interpreter()
                            .SetVariable("myk", null, typeof(string));

            Assert.AreEqual(null, target.Eval("myk"));
            Assert.AreEqual(true, target.Eval("myk == null"));
            Assert.AreEqual(typeof(string), target.Parse("myk").ReturnType);
        }
开发者ID:kornarakis,项目名称:DynamicExpresso,代码行数:9,代码来源:VariablesTest.cs

示例15: Parse_To_a_Delegate_With_One_Parameter

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

            var func = target.Parse<Func<string, int>>("arg.Length");

            Assert.AreEqual(4, func("ciao"));
            Assert.AreEqual(9, func("123456879"));
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:9,代码来源:TypedDelegatesTest.cs


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