Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

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;
}

Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

/// <summary>
/// Inserts one array into another array 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 insertion takes place.</param>
/// <param name="sourceArray">The source array that will be inserted.</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[] Insert<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");
    }

    Array.Resize(ref array, array.Length + sourceArray.Length);
    Array.Copy(array, index, array, index + sourceArray.Length, array.Length - sourceArray.Length - index);
    sourceArray.CopyTo(array, index);
    return array;
}

Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

/// <summary>
/// Removes a depth from the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose values are to be removed.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="depth">The depth of to be removed from the three dimensional sequence.</param>
/// <returns>Returns the updated three dimensional sequence.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1. Or depth is less then 0 or greater then the depth of the three dimensional sequence.
/// </exception>
public static T[] Remove3DDepth<T>(this T[] array, int width, int height, int depth)
{
    if (width < 1)
    {
        throw new ArgumentOutOfRangeException("width");
    }

    if (height < 1)
    {
        throw new ArgumentOutOfRangeException("height");
    }

    var length = width * height;
    if (depth < 0 || depth > (array.Length / length))
    {
        throw new ArgumentOutOfRangeException("depth");
    }

    return array.RemoveRange(depth * length, length);
}

Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

/// <summary>
/// Gets the depth of the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <returns>Returns the depth of the three dimensional sequence.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
public static int Get3DDepth<T>(this T[] array, int width, int height)
{
    if (width < 1)
    {
        throw new ArgumentOutOfRangeException("width");
    }

    if (height < 1)
    {
        throw new ArgumentOutOfRangeException("height");
    }

    return array.Length / (width * height);
}

Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

/// <summary>
/// Inserts a source array into the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="destinationArray">The destination array.</param>
/// <param name="depth">The depth of the three dimensional sequence where insertion takes place.</param>
/// <param name="sourceArray">The source array to be inserted.</param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1. Or depth is less then 0.
/// </exception>
/// <exception cref="ArgumentException">'sourceArray' must not be larger then '(width * height)'.</exception>
/// <remarks>The length of the 'sourceArray' parameter cannot be larger then '(width * height)' otherwise the data it contains would overwrite any data
/// stored at a deeper depth.</remarks>
/// <returns>Returns the updated 'destinationArray'.</returns>
public static T[] Insert3D<T>(this T[] destinationArray, int width, int height, int depth, T[] sourceArray)
{
    if (width < 1)
    {
        throw new ArgumentOutOfRangeException("width");
    }

    if (height < 1)
    {
        throw new ArgumentOutOfRangeException("height");
    }

    if (depth < 0)
    {
        throw new ArgumentOutOfRangeException("depth");
    }

    if (sourceArray == null || sourceArray.Length == 0)
    {
        return destinationArray;
    }

    // ensure source array is no greater then width * height
    if (sourceArray.Length > (width * height))
    {
        throw new ArgumentException("'sourceArray' must not be larger then '(width * height)'", "sourceArray");
    }

    if (sourceArray.Length < (width * height))
    {
        Array.Resize(ref sourceArray, width * height);
    }

    destinationArray = destinationArray.Insert(depth * (width * height), sourceArray);

    // return the updated array
    return destinationArray;
}

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume