/// <summary> /// Merges a range of fields from <paramref name="difference"/> /// <see cref="Tuple"/> starting at the specified index with the fields from /// <paramref name="origin"/> <see cref="Tuple"/> with the default value of <see cref="MergeBehavior"/>. /// </summary> /// <param name="origin">Tuple containing original values and receiving the data.</param> /// <param name="difference">Tuple with differences to merge with.</param> /// <param name="behavior">The merge behavior that will be used to resolve conflicts when both values /// from <paramref name="difference"/> and <paramref name="origin"/> are available.</param> public static void MergeWith(this Tuple origin, Tuple difference, MergeBehavior behavior) { MergeWith(origin, difference, 0, origin.Count, behavior); }
/// <summary> /// Merges a range of fields from <paramref name="difference"/> /// <see cref="Tuple"/> starting at the specified index with the fields from /// <paramref name="origin"/> <see cref="Tuple"/> with the specified /// <paramref name="behavior"/>. /// </summary> /// <param name="origin">Tuple containing original values and receiving the data.</param> /// <param name="difference">Tuple with differences to merge with.</param> /// <param name="startIndex">The index in the <paramref name="difference"/> tuple at which merging begins.</param> /// <param name="length">The number of elements to process.</param> /// <param name="behavior">The merge behavior that will be used to resolve conflicts when both values /// from <paramref name="difference"/> and <paramref name="origin"/> are available.</param> /// <exception cref="ArgumentException">Tuple descriptors mismatch.</exception> public static void MergeWith(this Tuple origin, Tuple difference, int startIndex, int length, MergeBehavior behavior) { if (difference == null) { return; } if (origin.Descriptor != difference.Descriptor) { throw new ArgumentException(string.Format(Strings.ExInvalidTupleDescriptorExpectedDescriptorIs, origin.Descriptor), "difference"); } var packedOrigin = origin as PackedTuple; var packedDifference = difference as PackedTuple; var useFast = packedOrigin != null && packedDifference != null; switch (behavior) { case MergeBehavior.PreferOrigin: if (useFast) { MergeTuplesPreferOriginFast(packedOrigin, packedDifference, startIndex, length); } else { MergeTuplesPreferOriginSlow(origin, difference, startIndex, length); } break; case MergeBehavior.PreferDifference: if (useFast) { PartiallyCopyTupleFast(packedDifference, packedOrigin, startIndex, startIndex, length); } else { PartiallyCopyTupleSlow(difference, origin, startIndex, startIndex, length); } break; default: throw new ArgumentOutOfRangeException("behavior"); } }