zoukankan      html  css  js  c++  java
  • “拼接”linq查询

    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; }
            }
        }
  • 相关阅读:
    二级JAVA考证笔记
    JAVA异常处理机制
    notepad++安装nppFTP
    nginx conf_ctx ****
    ngx_string()错误分析
    nginx
    char *p[] 和char**的思考
    LeetCode.接雨水
    LeetCode.atoi
    LeetCode.数字转罗马数字
  • 原文地址:https://www.cnblogs.com/wengyuli/p/1871134.html
Copyright © 2011-2022 走看看