hudong
4 天以前 3a3c5f5711a57439f34e772313fcbb18ba7885bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
 
namespace HH.WCS.Mobox3.pinggao.wms
{
    internal static class ExpressionHelper {
        public static Expression<Func<T, bool>> AndAlso<T>(this Expression<Func<T, bool>> left, Expression<Func<T, bool>> right) {
            var invokedExpr = Expression.Invoke(right, left.Parameters);
            return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(left.Body, invokedExpr), left.Parameters);
        }
        public class Person {
            public string Name { get; set; }
            public int Age { get; set; }
        }
        public static   void test() {
            var list=new List<Person>();
            list.Add(new Person {Age=1, Name="111" });
            list.Add(new Person { Age = 1, Name = "222" });
            list.Add(new Person { Age = 1, Name = "333" });
            list.Add(new Person { Age = 2, Name = "111" });
            list.Add(new Person { Age = 2, Name = "222" });
            list.Add(new Person { Age = 2, Name = "333" });
            list.Add(new Person { Age = 3, Name = "111" });
            list.Add(new Person { Age = 3, Name = "222" });
            list.Add(new Person { Age = 3, Name = "333" });
 
 
            Expression<Func<Person, bool>> expression = x => x.Age >= 2;
 
            expression = expression.AndAlso(x => x.Name =="111");
 
            var data=list.Where(expression.Compile()).ToList();
        }
    }
}