根据string获取对应类型的对应属性

 

  

 //获取类【OflSchApplyVM】的所有属性
                    PropertyInfo[] _PropertyInfo = typeof(OflSchApplyVM).GetProperties();

                    //对应属性
                    PropertyInfo _pro = null;

                    //获取属性名=【sort】的属性
                    foreach (var item in _PropertyInfo)
                    {
                        if (item.Name == sort)
                        {
                            _pro = item;
                        }
                    }

                    //List<T>排序
                    if (_pro != null)
                    {

                        if (order == "desc")
                        {

                            lstPage = lstPage.OrderByDescending(a => _pro).ToList();
                        }
                        if (order == "asc")
                        {
                            lstPage = lstPage.OrderBy(a => _pro).ToList();
                        }

                    }

  

posted @ 2016-09-02 16:01  人生为卒  阅读(796)  评论(0编辑  收藏  举报