Merge() public static method

public static Merge ( DiffOperation left, DiffOperation right ) : DiffOperation
left DiffOperation
right DiffOperation
return DiffOperation
示例#1
0
        public static ListDiff Merge(ListDiff left, ListDiff right)
        {
            List <int> keys = left.Operations.Keys.ToList <int>();

            foreach (var kv in right.Operations)
            {
                if (!left.Operations.ContainsKey(kv.Key))
                {
                    keys.Add(kv.Key);
                }
            }

            ListDiff diff = new ListDiff();

            foreach (int key in keys)
            {
                if (left.Operations.ContainsKey(key) && right.Operations.ContainsKey(key))
                {
                    diff.Operations[key] = DiffOperation.Merge(left.Operations[key], right.Operations[key]);
                }
                else if (left.Operations.ContainsKey(key))
                {
                    diff.Operations[key] = left.Operations[key];
                }
                else if (right.Operations.ContainsKey(key))
                {
                    diff.Operations[key] = right.Operations[key];
                }
            }

            return(diff);
        }
示例#2
0
        public static CompoundDiff Merge(CompoundDiff left, CompoundDiff right)
        {
            // Find combined key list
            List <object> keys = left.Operations.Keys.ToList <object>();

            foreach (var kv in right.Operations)
            {
                if (!left.Operations.ContainsKey(kv.Key))
                {
                    keys.Add(kv.Key);
                }
            }

            // Merge the operations for each key.
            CompoundDiff diff = new CompoundDiff();

            foreach (object key in keys)
            {
                if (left.Operations.ContainsKey(key) && right.Operations.ContainsKey(key))
                {
                    diff.Operations[key] = DiffOperation.Merge(left.Operations[key], right.Operations[key]);
                }
                else if (left.Operations.ContainsKey(key))
                {
                    diff.Operations[key] = left.Operations[key];
                }
                else if (right.Operations.ContainsKey(key))
                {
                    diff.Operations[key] = right.Operations[key];
                }
            }

            return(diff);
        }