Esempio n. 1
0
        public bool Equals(CollectionEvent <T> otherEvent)
        {
            if (otherEvent == null || _eventType != otherEvent._eventType || !ReferenceEquals(_sender, otherEvent._sender))
            {
                return(false);
            }

            switch (_eventType)
            {
            case Changed:
                return(true);

            case Cleared: {
                var x = _eventArgs as ClearedEventArgs;
                var y = otherEvent._eventArgs as ClearedEventArgs;
                return(x != null && y != null && x.Count == y.Count && x.Full == y.Full && x.Start == y.Start);
            }

            case Added:
            case Removed: {
                var x = _eventArgs as ItemCountEventArgs <T>;
                var y = otherEvent._eventArgs as ItemCountEventArgs <T>;
                return(y != null && x != null && x.Count == y.Count && x.Item.IsSameAs(y.Item));
            }

            case Inserted:
            case RemovedAt: {
                var x = _eventArgs as ItemAtEventArgs <T>;
                var y = otherEvent._eventArgs as ItemAtEventArgs <T>;
                return(y != null && x != null && x.Index == y.Index && x.Item.IsSameAs(y.Item));
            }

            default:
                throw new ApplicationException($"Illegal Action: {_eventType}");
            }
        }
Esempio n. 2
0
 public static CollectionEventConstraint <T> RaisesCollectionChangedEventFor <T>(IListenable <T> collection) => new CollectionEventConstraint <T>(collection, new[] { CollectionEvent.Changed(collection) });