Exemple #1
0
        /// <summary>
        /// Merges a <see cref="ModelValueChangeEvent"/> into the current event.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        protected override bool OnMerge(ModelEvent e)
        {
            // Ensure the events are for the same reference property
            var listChange = (ModelListChangeEvent)e;

            if (listChange.Property != Property)
            {
                return(false);
            }

            // Highly likely not to be right
            var mergeAdded = Added.ToList();

            mergeAdded.RemoveAll(i => listChange.Removed.Contains(i));

            var mergeRemoved = Removed.ToList();

            mergeRemoved.RemoveAll(i => listChange.Added.Contains(i));

            mergeAdded   = mergeAdded.Union(listChange.Added.Where(i => !Removed.Contains(i))).ToList();
            mergeRemoved = mergeRemoved.Union(listChange.Removed.Where(i => !Added.Contains(i))).ToList();

            Added   = mergeAdded.ToArray();
            Removed = mergeRemoved.ToArray();


            var mergeAddedIds = AddedIds.ToList();

            mergeAddedIds.RemoveAll(i => listChange.RemovedIds.Contains(i));

            var mergeRemovedIds = RemovedIds.ToList();

            mergeRemovedIds.RemoveAll(i => listChange.AddedIds.Contains(i));

            mergeAddedIds   = mergeAddedIds.Union(listChange.AddedIds.Where(i => !RemovedIds.Contains(i))).ToList();
            mergeRemovedIds = mergeRemovedIds.Union(listChange.RemovedIds.Where(i => !AddedIds.Contains(i))).ToList();

            AddedIds   = mergeAddedIds.ToArray();
            RemovedIds = mergeRemovedIds.ToArray();

            return(true);
        }