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

it2025-04-10  8

  

//获取类【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(); } }

  

转载于:https://www.cnblogs.com/lhlong/p/5833863.html

最新回复(0)