Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only
/// <summary>
/// Replaces a sequence of array entries at the specified index.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="index">The index in the destination array where replacement takes place.</param>
/// <param name="sourceArray">The source array that will replace the existing entries.</param>
/// <returns>Returns the resized and updated destination array.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// If 'index' is out of bounds of the destination array.
/// </exception>
public static T[] Replace<T>(this T[] array, int index, T[] sourceArray)
{
if (array == null || sourceArray == null || sourceArray.Length == 0)
{
return array;
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
}
if (index > array.Length - 1)
{
throw new ArgumentOutOfRangeException("index");
}
var expandSize = (index + sourceArray.Length) - array.Length;
if (expandSize > 0)
{
Array.Resize(ref array, array.Length + expandSize);
}
sourceArray.CopyTo(array, index);
return array;
}