public new int this[Good good] { get { if (ContainsKey(good)) { return(base[good]); } return(0); } set { int delta = 0; if (ContainsKey(good)) { delta = value - base[good]; base[good] = value; } else { delta = value; Add(good, value); } OnCollectionChange?.Invoke(this, new GoodsCollectionEventArgs { Good = good, Value = delta }); } }
public void UpdateType() { SimAdultBtn.Selected = AType[1] == 'a'; SimChildBtn.Selected = AType[1] == 'c'; SimMaleBtn.Selected = AType[0] == 'm'; SimFemaleBtn.Selected = AType[0] == 'f'; SimSkinLgtBtn.Selected = SkinType == "lgt"; SimSkinMedBtn.Selected = SkinType == "med"; SimSkinDrkBtn.Selected = SkinType == "drk"; OnCollectionChange?.Invoke(); }
//private void SubscribeLoggerToEvents() //{ // OnCollectionChange += Students_OnCollectionChange; // OnInvalidInput += Student_OnInvalidInput; //} public void AddStudent(Student student) { _validator.ValidateNotNull(_students, nameof(_students)); try { _validator.ValidateNotNull(student, nameof(student)); _validator.ValidateNotNullOrEmptyString(student.FirstName, nameof(student.FirstName)); _validator.ValidateNotNullOrEmptyString(student.LastName, nameof(student.LastName)); } catch (InitializationIssue e) { OnInvalidInput?.Invoke(this, new InvalidStudentInputEventArgs(e, student)); throw new InvalidStudentInput("Can't add student. Student is invalid", e, student); } _students.Add(student); OnCollectionChange?.Invoke(this, new StudentCollectinChangedEventArgs(CollectionChangeAction.Add, _students, student)); }
//Добавление с заменой или без по уникальному идентификатору public void AddWithID(Item item, bool replaceFlag = false) { if (item.ID == null) { item.ID = ++_idCounter; Add(item); } else { if (Contains(item) && replaceFlag) { this[IndexOfID(item)] = item; } else { //item.ID = ++_idCounter; Add(item); } } OnCollectionChange?.Invoke(); }
public void Clear() { _items.Clear(); OnCollectionChange?.Invoke(_instanceName); }
public void Add(T item) { _items.Add(item); OnCollectionChange?.Invoke(_instanceName); }
//Метод удаления из списка и дальнейшая сигнализация о изменении в списке public new void Remove(Item item) { base.Remove(item); OnCollectionChange?.Invoke(); }