//------------------------------------------------------------------------------------- /// <summary> /// Снимает фильтр со списка. /// </summary> public void RemoveFilter() { filter = null; filterMethod = null; Refresh(); }
//------------------------------------------------------------------------------------- /// <summary> /// Устанавливает фильтрацию списка. /// </summary> /// <param name="filterMethod">Метод фильтрации данных. Имеет вид: bool Method(object obj)</param> public void ApplyFilter(Func<object,bool> filterMethod) { if(filterMethod == null) RemoveFilter(); else { this.filterMethod = filterMethod; filter = new ValuesTrio<PropertyDescriptor, PulsarFilterConditions, IEnumerable>(null, PulsarFilterConditions.CustomFiltering, null); Refresh(); } }
/// <summary> /// Устанавливает фильтрацию списка. /// </summary> /// <param name="propName">Наименование свойства, по которому устанавливается фильтрация.</param> /// <param name="condition">Условие фильтрации.</param> /// <param name="variants">Список вариантов значения свойства.</param> public void ApplyFilter(string propName, PulsarFilterConditions condition, IEnumerable variants) { if(variants is string) variants = new object[1] { variants }; filterMethod = null; Type t = itemType; if(t == null) { t = List.GetType(); if(t.IsGenericType == false) throw new Exception("Метод Sort по указанному свойству не поддерживается для не generic коллекций!"); t = t.GetGenericArguments()[0]; } PropertyDescriptor d = null; if(t.IsValueType || t == typeof(String)) d = new PrimitiveValuePropertyDescriptor(t); else { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(t); if(props.Count == 0) throw new Exception("Класс элемента списка не имеет публичных свойств!"); d = props.Find(propName, false); } if(d == null) throw new ArgumentException(String.Format("У типа \"{1}\" отсутствует публичное свойство \"{0}\"!", propName, t.FullName), "propName"); filter = new ValuesTrio<PropertyDescriptor, PulsarFilterConditions, IEnumerable>(d, condition, variants ?? new List<object>()); Refresh(); }
//------------------------------------------------------------------------------------- /// <summary> /// Устанавливает фильтрацию списка. /// </summary> /// <param name="condition">Условие фильтрации.</param> /// <param name="variants">Список вариантов значений списка.</param> public void ApplyFilter(PulsarFilterConditions condition, IEnumerable variants) { filter = new ValuesTrio<PropertyDescriptor, PulsarFilterConditions, IEnumerable>(null, condition, variants ?? new List<object>()); Refresh(); }
private void RefreshInternal() { if(IsFiltered == false) index = null; else if(filter.Value2 == PulsarFilterConditions.CustomFiltering && filterMethod == null) { filter = null; filterMethod = null; index = null; } else { if(index == null) index = new List<int>(); else index.Clear(); for(int a = 0; a < _list.Count; a++) if(PassFilterCheck(_list[a])) index.Add(a); } if(IsSorted) SortInternal(); }