Esempio n. 1
0
        /// <summary>
        /// Merges two Diff operation into a single operation.
        /// </summary>
        static public DiffOperation Merge(DiffOperation left, DiffOperation right)
        {
            // Remove always trumps other operations.
            if (right is RemoveOperation)
            {
                return(right);
            }
            if (left is RemoveOperation)
            {
                return(left);
            }

            // Change operation trumps other operations and right changes take precedence over
            // left changes.
            if (right is ChangeOperation)
            {
                return(right);
            }
            if (left is ChangeOperation)
            {
                return(left);
            }

            // Recursively merge array and object operations.
            System.Diagnostics.Debug.Assert(left.GetType() == right.GetType());
            if (left is ChangeObjectOperation)
            {
                return(ChangeObjectOperation.Merge(left as ChangeObjectOperation, right as ChangeObjectOperation));
            }
            if (left is ChangePositionArrayOperation)
            {
                return(ChangePositionArrayOperation.Merge(left as ChangePositionArrayOperation, right as ChangePositionArrayOperation));
            }
            if (left is ChangeIdArrayOperation)
            {
                return(ChangeIdArrayOperation.Merge(left as ChangeIdArrayOperation, right as ChangeIdArrayOperation));
            }

            System.Diagnostics.Debug.Assert(false);
            return(null);
        }
Esempio n. 2
0
        public static ChangePositionArrayOperation Merge(ChangePositionArrayOperation left, ChangePositionArrayOperation right)
        {
            PositionArrayDiff diff = PositionArrayDiff.Merge(left.Diff, right.Diff);

            return(new ChangePositionArrayOperation(diff));
        }