public void Remove(object obj) { Debug.Assert(obj != null, "obj为null"); if (obj == null) { return; } if (_currentCodon == null) { return; } IBindingListEx bindingList = GetBindingList(_currentCodon); if (bindingList == null) { return; } Debug.Assert(bindingList.Contains(obj), "_bindingList中没有指定对象"); if (bindingList.Contains(obj) == false) { return; } if (_currentCodon.Compatible(obj)) { bindingList.Remove(obj); } }
public void Remove <T>(Filter <T> filter) where T : class { Debug.Assert(filter != null, "Filter 为 null"); if (filter == null) { return; } if (_currentCodon == null) { return; } IBindingListEx bindingList = GetBindingList(_currentCodon); if (bindingList == null || bindingList.Count == 0) { return; } Type tType = typeof(T); if (_currentCodon.UpwardCompatible(tType) == false && _currentCodon.Compatible(tType) == false) { return; } List <object> willbeDelete = new List <object>(); for (int i = 0; i < bindingList.Count; i++) { object obj = bindingList[i]; //在使用复合 codon 时,BindingList 中会存在多种不同类型的对象 //所以必须先判断对象是否是泛型参数类型的向下兼容类型 if (Compatible(tType, obj.GetType()) && filter((T)obj)) { willbeDelete.Add(obj); } } foreach (var item in willbeDelete) { bindingList.Remove(item); } }
/// <summary> /// 把目标对象移动到另一个对象之后 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sourceFilter"></param> /// <param name="targetFilter"></param> public void MoveAfter <T>(Filter <T> sourceFilter, Filter <T> targetFilter) where T : class { object sourceObj, targetObj; GetMoveObject <T>(sourceFilter, targetFilter, out sourceObj, out targetObj); //Debug.Assert(sourceObj != null && targetObj != null, "指定的对象为null"); if (sourceObj == null && targetObj == null) { return; } Debug.Assert(sourceObj != targetObj, "指定的两个对象是同一个对象"); if (sourceObj == targetObj) { return; } if (_currentCodon == null) { return; } IBindingListEx bindingList = GetBindingList(_currentCodon); int sourceIndex = bindingList.IndexOf(sourceObj); int targetIndex = bindingList.IndexOf(targetObj); //如果targetObj刚好在beforeObj之后,就无需移动了 if (sourceIndex - targetIndex == 1) { return; } bindingList.Remove(sourceObj); //要重新 IndexOf(beforeObj) ,因为targetObj被remove之后,beforeObj的下标就可能被改变了 bindingList.Insert(bindingList.IndexOf(targetObj) + 1, sourceObj); }