예제 #1
0
        public bool TryRemove(T item)
        {
            RejectableArgs <T> eventObject = new RejectableArgs <T>(Operation.Remove, item, internalList.Count);

            OnBeforeChangeEvent(eventObject);
            if (eventObject.IsOperationRejected || internalList.IndexOf(item) < 0)
            {
                return(false);
            }
            internalList.Remove(item);
            OnChangedEvent(new ListChangedEventArgs <T>(Operation.Remove, item, internalList.Count));
            return(true);
        }
예제 #2
0
        public bool TryAdd(T item)
        {
            RejectableArgs <T> eventObject = new RejectableArgs <T>(Operation.Add, item, internalList.Count);

            OnBeforeChangeEvent(eventObject);
            if (eventObject.IsOperationRejected)
            {
                return(false);
            }
            internalList.Add(item);
            OnChangedEvent(new ListChangedEventArgs <T>(Operation.Add, item, internalList.Count));
            return(true);
        }
예제 #3
0
        public void Add(T item)
        {
            RejectableArgs <T> eventObject = new RejectableArgs <T>(Operation.Add, item, internalList.Count);

            OnBeforeChangeEvent(eventObject);
            if (item.ToString().Trim().Length < 1)
            {
                throw new InvalidOperationException();
            }
            if (eventObject.IsOperationRejected)
            {
                throw new OperationRejectedException(String.Format("Failed to {0} item '{1}'.", eventObject.Operation, eventObject.Value));
            }
            internalList.Add(item);
            OnChangedEvent(new ListChangedEventArgs <T>(Operation.Add, item, internalList.Count));
        }
예제 #4
0
        public void Remove(T item)
        {
            RejectableArgs <T> eventObject = new RejectableArgs <T>(Operation.Remove, item, internalList.Count);

            OnBeforeChangeEvent(eventObject);
            if (internalList.IndexOf(item) < 0)
            {
                throw new InvalidOperationException();
            }
            else if (eventObject.IsOperationRejected)
            {
                throw new OperationRejectedException(String.Format("Failed to {0} item '{1}'.", eventObject.Operation, eventObject.Value));
            }
            internalList.Remove(item);
            OnChangedEvent(new ListChangedEventArgs <T>(Operation.Remove, item, internalList.Count));
        }
예제 #5
0
 private void OnBeforeChangeEvent(RejectableArgs <T> rejectableEventArgs) => BeforeChange?.Invoke(this, rejectableEventArgs);