private void ApplyFilter() { if (string.IsNullOrEmpty(this.filter)) { return; } FilterSpec spec = new FilterSpec(filter); if (string.IsNullOrEmpty(spec.Subject) || string.IsNullOrEmpty(spec.Value) || spec.FilterType == FilterType.None) { if (this.Count == this.manager.Count) { return; } } this.Refresh(); }
private void Refresh() { FilterSpec fSpec = new FilterSpec(filter); //count = this.Count; //for (int i = 0; i < count; i++) //{ // PropertyInfo prop = typeof(T).GetProperty(spec.Subject); // while (i < count && Belongs(this[i], spec)) // { // //bad // this.Remove(this[i]); // count = this.Count; // } //} //for (int i = 0; i < this.data.Count; i++) //{ // if (!this.Belongs(this.data[i], spec)) // base.Add(this.data[i]); //} lock (this) { List <T> filteredItems = new List <T>(); try { FilterSpecCollection specs = new FilterSpecCollection(this.filterCollection); specs.Add(fSpec); int counter = 0; foreach (FilterSpec spec in specs) { if (counter == 0) { foreach (KeyValuePair <long, T> kvp in this.manager) { if (this.Belongs(kvp.Value, spec)) { filteredItems.Add(kvp.Value); } } } else { for (int i = 0; i < filteredItems.Count; i++) { if (!this.Belongs(filteredItems[i], spec)) { filteredItems.RemoveAt(i--); } } } counter++; } this.ClearItems(); filteredItems.ForEach(delegate(T item) { base.Add(item); }); } catch (Exception) { throw; } } }