public T ReadProperty <T>(params string[] names) { foreach (var name in names) { var description = $"{ItemName}::{name}"; try { var propertyInfo = ItemType.GetProperty(name); if (propertyInfo == null) { continue; } if (!propertyInfo.CanRead) { throw new Exception($"Cannot read {description}"); } return((T)propertyInfo.GetValue(Item)); } catch (Exception e) { ExceptionHandler.Log(e, $"Cannot read {description} without errors!"); throw; } } throw new Exception($"Cannot find {names} at {ItemName}."); }
public async Task <List <object> > GetPageAsync(SortChangeEvent sort, GridSearch search) { if (sort == null) { return((await GetListAsync(search)) .Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList()); } else { PropertyInfo prop = ItemType.GetProperty(sort.SortId); if (sort.Direction == SortDirection.Desc) { return((await GetListAsync(search)).OrderByDescending(x => prop.GetValue(x, null)) .Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList()); } else { return((await GetListAsync(search)).OrderBy(x => prop.GetValue(x, null)) .Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList()); } } }