public bool Remove(Student st) { bool b = false; foreach (var s in list.Where(kpv => kpv.Value == st).ToList()) { list.Remove(s.Key); StudentChanged?.Invoke(this, new StudentsChangedEventArgs <TKey>(CollectionName, Action.Remove, "Element was removed", s.Key)); s.Value.PropertyChanged -= PropChanged; b = true; } return(b); }
public Student this[TKey index] { get { return(list[index]); } set { try { list[index] = value; list[index].PropertyChanged += PropChanged; StudentChanged?.Invoke(this, new StudentsChangedEventArgs <TKey>(CollectionName, Action.Property, "Element was changed", index)); StudentReferenceChanged?.Invoke(this, new StudentListHandlerEventArgs(CollectionName, "Element was changed", list[index])); } catch { } } }
public void AddStudents(TKey key, params Student[] arr) { if (arr.Length == 0) { arr = new Student[0]; StudentsCountChanged?.Invoke(this, new StudentListHandlerEventArgs(CollectionName, "Added new element", arr[0])); } if (list == null) { list = new Dictionary <TKey, Student>(); } for (int i = 0; i < arr.Length; i++) { list.Add(key, arr[i]); StudentsCountChanged?.Invoke(this, new StudentListHandlerEventArgs(CollectionName, "Added new element", arr[i])); StudentChanged?.Invoke(this, new StudentsChangedEventArgs <TKey>(CollectionName, Action.Add, "Added new element", key)); list[key].PropertyChanged += PropChanged; } }
public void PropChanged(object sender, PropertyChangedEventArgs e) { TKey key = list.FirstOrDefault(i => i.Value.Equals(sender)).Key; StudentChanged?.Invoke(this, new StudentsChangedEventArgs <TKey>(CollectionName, Action.Property, e.PropertyName, key)); }