本文整理汇总了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));
}
示例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));
}
示例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));
}
示例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());
}