public void Sort(string propertyName, string direction) { if (string.IsNullOrEmpty(propertyName)) { CurrentPageNumber = 1; Calculate(CurrentPageNumber); return; } Func <T, object> propertyGetter; if (!sortCache.TryGetValue(propertyName, out propertyGetter)) { var prop = typeof(T).GetProperty(propertyName); propertyGetter = obj => prop.GetValue(obj, null); if (prop == null) { CurrentPageNumber = 1; Calculate(CurrentPageNumber); return; } } if (string.IsNullOrEmpty(direction) || direction.ToLower() == "descending") { AllObjects = new ObservableCollection <T>(AllObjects.OrderByDescending(propertyGetter)); } else { AllObjects = new ObservableCollection <T>(AllObjects.OrderBy(propertyGetter)); } CurrentPageNumber = 1; Calculate(CurrentPageNumber); }
public void Sort(string propertyName, string direction) { PropertyInfo prop; string[] arrProp = propertyName.Split('.'); if (arrProp.Length > 1) { //Type.GetType("DA.BE.Usuario, DA.BE") //Type tipoBase = Type.GetType("DA.BE."+arrProp[0]+", DA.BE"); // prop = tipoBase.GetRuntimeProperty(arrProp[1]); prop = typeof(T).GetProperty(arrProp[0]); } else { prop = typeof(T).GetProperty(propertyName); } if (prop != null) { try { Type propertyType = Type.GetType(prop.PropertyType.FullName + ", " + prop.PropertyType.FullName.Split('.')[0] + "." + prop.PropertyType.FullName.Split('.')[1]); if (string.IsNullOrEmpty(direction) || direction.ToLower() == "descending") { AllObjects = new ObservableCollection <T>(AllObjects.OrderByDescending(x => prop.GetValue(x, null)).ToList()); } else { // var list = AllObjects.OrderBy(x => Convert.ChangeType(prop.GetValue(x, null), propertyType)); //var list = AllObjects.OrderBy(x => (propertyType) prop.GetValue(x, null)); // var list2 = AllObjects.OrderBy(x => prop.GetValue(x, null)).ToList(); AllObjects = new ObservableCollection <T>(AllObjects.OrderBy(x => prop.GetValue(x, null)).ToList()); } CurrentPageNumber = 1; SetCurrentPageItems(); } catch (Exception e) { Logger.Log.Error("Error en el ordenamiento: " + e.Message); } } }
public void Sort(string propertyName, string direction) { PropertyInfo prop = typeof(T).GetProperty(propertyName); if (string.IsNullOrEmpty(direction) || direction.ToLower() == "descending") { AllObjects = new ObservableCollection <T>(AllObjects.OrderByDescending(x => prop.GetValue(x, null))); } else { AllObjects = new ObservableCollection <T>(AllObjects.OrderBy(x => prop.GetValue(x, null))); } CurrentPageNumber = 1; SetCurrentPageItems(); }