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


C# Interpreter.ParseAsDelegate方法代码示例

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


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

示例1: Parse_To_a_Delegate_With_No_Parameters

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

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

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

示例2: Parse_To_a_Delegate

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

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

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

示例3: Parse_To_a_Custom_Delegate

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

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

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

示例4: Parse_To_a_Delegate_With_Two_Parameters

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

			var func = target.ParseAsDelegate<Func<double, double, double>>("arg1 * arg2");

			Assert.AreEqual(6, func(3, 2));
			Assert.AreEqual(50, func(5, 10));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:9,代码来源:GenerateDelegatesTest.cs

示例5: Parse_To_a_Delegate_With_One_Parameter

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

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

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

示例6: Parse_To_a_Delegate_With_Two_Parameters_With_Custom_Name

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

			var argumentNames = new string[] { "x", "y" };
			var func = target.ParseAsDelegate<Func<double, double, double>>("x * y", argumentNames);

			Assert.AreEqual(6, func(3, 2));
			Assert.AreEqual(50, func(5, 10));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:10,代码来源:GenerateDelegatesTest.cs

示例7: Parse_To_a_Delegate_With_One_Parameter_With_Custom_Name

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

			var argumentName = "val"; // if not specified the delegate parameter is used which is "arg"
			var func = target.ParseAsDelegate<Func<string, int>>("val.Length", argumentName);

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

示例8: Linq_Where

		public void Linq_Where()
		{
			var customers = new List<Customer> { 
                                    new Customer() { Name = "David", Age = 31, Gender = 'M' },
                                    new Customer() { Name = "Mary", Age = 29, Gender = 'F' },
                                    new Customer() { Name = "Jack", Age = 2, Gender = 'M' },
                                    new Customer() { Name = "Marta", Age = 1, Gender = 'F' },
                                    new Customer() { Name = "Moses", Age = 120, Gender = 'M' },
                                    };

			string whereExpression = "customer.Age > 18 && customer.Gender == 'F'";

			var interpreter = new Interpreter();
			Func<Customer, bool> dynamicWhere = interpreter.ParseAsDelegate<Func<Customer, bool>>(whereExpression, "customer");

			Assert.AreEqual(1, customers.Where(dynamicWhere).Count());
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:17,代码来源:OtherTests.cs

示例9: Implicit_conversion_operator_for_lambda

		public void Implicit_conversion_operator_for_lambda()
		{
			var target = new Interpreter()
					.SetVariable("x", new TypeWithImplicitConversion(10));

			var func = target.ParseAsDelegate<Func<int>>("x");
			int val = func();

			Assert.AreEqual(10, val);
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:10,代码来源:OperatorsTest.cs

示例10: Interpreter

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

			var myDelegate = target.ParseAsDelegate<TestDelegate>("x + y");

			// parameter 'z' is not used but the delegate accept it in any case without problem
			Assert.AreEqual(3, myDelegate(1, 2, 123123));
			Assert.AreEqual(24, myDelegate(21, 3, 433123));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:10,代码来源:ParametersTest.cs

示例11: Return_Type_Mismatch_Cause_An_Exception

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

			// expected a double but I return a string
			target.ParseAsDelegate<Func<double>>("\"ciao\"");
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:7,代码来源:GenerateDelegatesTest.cs


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