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


C# Interpreter.ParseAsExpression方法代码示例

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


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

示例1: Parse_as_LambdaExpression_with_parameter

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

			Expression<Func<double, double>> lambdaExpression = target.ParseAsExpression<Func<double, double>>("arg + 5");

			Assert.AreEqual(15, lambdaExpression.Compile()(10));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:8,代码来源:GenerateLambdaTest.cs

示例2: Parse_To_a_Delegate_With_Two_Parameters

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

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

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

示例3: 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 lambdaExpression = target.ParseAsExpression<Func<double, double, double>>("x * y", argumentNames);

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

示例4: Linq_Queryable_Expression_Where

		public void Linq_Queryable_Expression_Where()
		{
			IQueryable<Customer> 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' },
			}).AsQueryable();

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

			var interpreter = new Interpreter();
			Expression<Func<Customer, bool>> expression = interpreter.ParseAsExpression<Func<Customer, bool>>(whereExpression, "customer");

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


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