Ejemplo n.º 1
0
        public static ListDiff <TSource, TDestination> MergeInto <TSource, TDestination> (this IList <TSource> source, IEnumerable <TDestination> destination, Func <TSource, TDestination, bool> match, Func <TDestination, TSource> create, Action <TSource, TDestination> update, Action <TSource> delete)
        {
            var diff = new ListDiff <TSource, TDestination> (source, destination, match);

            var p = 0;

            foreach (var a in diff.Actions)
            {
                if (a.ActionType == ListDiffActionType.Add)
                {
                    source.Insert(p, create(a.DestinationItem));
                    p++;
                }
                else if (a.ActionType == ListDiffActionType.Remove)
                {
                    delete(a.SourceItem);
                    source.RemoveAt(p);
                }
                else
                {
                    update(a.SourceItem, a.DestinationItem);
                    p++;
                }
            }

            return(diff);
        }
Ejemplo n.º 2
0
        public static ListDiff <T, T> MergeInto <T> (this IList <T> source, IEnumerable <T> destination, Func <T, T, bool> match)
        {
            var diff = new ListDiff <T, T> (source, destination, match);

            var p = 0;

            foreach (var a in diff.Actions)
            {
                if (a.ActionType == ListDiffActionType.Add)
                {
                    source.Insert(p, a.DestinationItem);
                    p++;
                }
                else if (a.ActionType == ListDiffActionType.Remove)
                {
                    source.RemoveAt(p);
                }
                else
                {
                    p++;
                }
            }

            return(diff);
        }