动态创建Lambda 表达式的例子!

来源:互联网 发布:linux给其他用户授权 编辑:程序博客网 时间:2024/05/16 08:59

 static class Extend
    {
        public static IList<T> GetALL<T>(this IList<T> table, string field) where T : class
        {
            var pm = Expression.Parameter(typeof(T), "f");
            var body = Expression.Property(pm, field);
            var lambdaEx = Expression.Lambda<Func<T, Int32>>(body, pm);
            return table.OrderBy(lambdaEx.Compile()).ToList();
        }

        public static IQueryable<SurveryData> GetALL(this IQueryable<SurveryData> table, string field)
        {
            var result = table.OrderBy(s => s.SurveryPoint.SurveryPointName);
            return result;
        }
    } 

原创粉丝点击