static void Main(string[] args)
        {
            List<Person> list = new List<Person>() { 
                new Person(){ Age=20, Name="wengyuli", Parts=new Part(){ Name="123"}},
                new Person(){ Age=30, Name="chenyang", Parts=new Part(){ Name="123456"}},
                new Person(){ Age=40, Name="heshuai", Parts=new Part(){ Name="123"}},
                new Person(){ Age=50, Name="heyunlong", Parts=new Part(){ Name="123456"}}
            };

            var c = Expression.Parameter(typeof(Person), "m");

            Expression condition = Expression.Constant(false);


            Expression con = Expression.Call(
                Expression.Property(c,typeof(Person).GetProperty("Name")),
                typeof(string).GetMethod("StartsWith",new Type[]{typeof(string)}),
                Expression.Constant("wengyuli"));

            condition = Expression.Or(con, condition); 
            Expression<Func<Person, bool>> end = Expression.Lambda<Func<Person, bool>>(condition, new ParameterExpression[] { c });
        }
        
        class Person
        {
            public string Name { set; get; }
            public int Age { set; get; }
            public Part Parts { set; get; }
        }

        class Part
        {
            public string Name { set; get; }
        }
    }

相关文章:

  • 2021-10-10
  • 2022-12-23
  • 2021-06-01
  • 2021-11-29
  • 2021-05-28
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-18
  • 2021-09-09
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案