Calendar
Mo | Tu | We | Th | Fr | Sa | Su |
---|
30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
Archive
- 2002
- 2003
- 2004
- 2005
- 2006
- 2007
- 2008
- 2009
- 2010
- 2011
- 2012
- 2013
- 2014
- 2015
- 2016
- 2019
- 2020
|
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>
/// Determines weather or not all the characters in a string are all the same.
/// </summary>
/// <param name="value">The value to check for.</param>
/// <returns>true is all characters are the same, otherwise false.</returns>
public static bool AllTheSame(this string value)
{
#if UNITY3D
if (!StringExtensionMethods.IsNullOrWhiteSpace(value))
#else
if (!string.IsNullOrWhiteSpace(value))
#endif
{
var clone = new string(value[0], value.Length);
return clone == value;
}
return false;
}
#if UNITY3D
public static bool IsNullOrWhiteSpace(this string value)
{
if (value == null)
{
return true;
}
for (var i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}
return true;
}
#endif
}
921b6831-b717-421d-ba8f-8ad18fd0f56d|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only namespace System.Collections
{
/// <summary>
/// Provides extension methods for the IList interface.
/// </summary>
public static class IListExtensionMethods
{
/// <summary>Swaps the specified items in a list.</summary>
/// <param name="list">The list.</param>
/// <param name="indexA">The index of item A.</param>
/// <param name="indexB">The index of item B.</param>
/// <param name="remove">If set to <c>true</c> items will be removed and re-inserted.</param>
public static void Swap(this IList list, int indexA, int indexB, bool remove)
{
if (indexA == indexB)
{
return;
}
indexA.IsInRange(0, list.Count - 1, true, "indexA is out of range.");
indexB.IsInRange(0, list.Count - 1, true, "indexB is out of range.");
if (remove)
{
var first = Math.Min(indexA, indexB);
var second = Math.Max(indexA, indexB);
var tempA = list[first];
var tempB = list[second];
list.RemoveAt(second);
list.RemoveAt(first);
list.Insert(first, tempB);
list.Insert(second, tempA);
}
else
{
var temp = list[indexA];
list[indexA] = list[indexB];
list[indexB] = temp;
}
}
/// <summary>Swaps the specified items in a list.</summary>
/// <param name="list">The list.</param>
/// <param name="indexA">The index of item A.</param>
/// <param name="indexB">The index of item B.</param>
/// <remarks>Items are swapped and not removed or inserted.</remarks>
public static void Swap(this IList list, int indexA, int indexB)
{
Swap(list, indexA, indexB, false);
}
/// <summary>Swaps the specified items in a list and return true if successful.</summary>
/// <param name="list">The list.</param>
/// <param name="indexA">The index of item A.</param>
/// <param name="indexB">The index of item B.</param>
/// <remarks>Items are swapped and not removed or inserted.</remarks>
/// <returns>true if successful.</returns>
public static bool TrySwap(this IList list, int indexA, int indexB)
{
try
{
Swap(list, indexA, indexB);
}
catch
{
return false;
}
return true;
}
/// <summary>Swaps the specified items in a list and return true if successful.</summary>
/// <param name="list">The list.</param>
/// <param name="indexA">The index of item A.</param>
/// <param name="indexB">The index of item B.</param>
/// <param name="remove">If set to <c>true</c> items will be removes and re-inserted.</param>
/// <returns>true if successful.</returns>
public static bool TrySwap(this IList list, int indexA, int indexB, bool remove)
{
try
{
Swap(list, indexA, indexB, remove);
}
catch
{
return false;
}
return true;
}
}
}
fba1eb61-9978-4f0f-b9cd-34b808c00e42|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Removes a range of entries inside an array.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="index">The start index where entries will be removed from.</param>
/// <param name="length">The number of entries to be removed.</param>
/// <returns>
/// Returns the resized and updated destination array.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">index</exception>
public static T[] RemoveRange<T>(this T[] array, int index, int length)
{
if (length < 1)
{
return array;
}
if (index < 0 || index > array.Length - 1)
{
throw new ArgumentOutOfRangeException("index");
}
if (index + length > array.Length - 1)
{
Array.Resize(ref array, index);
return array;
}
var endLength = Math.Max(0, Math.Min(array.Length - index, array.Length - (index + length)));
var tempArray = new T[endLength];
Array.Copy(array, index + length, tempArray, 0, endLength);
Array.Resize(ref array, array.Length - length);
tempArray.CopyTo(array, array.Length - endLength);
return array;
}
f468b7a3-87f8-4dd1-9ff8-ab01d10053ca|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Moves the specified entries in the array by a set ammount.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="index">The start index where entries will be moved from.</param>
/// <param name="length">The number of entries to be moved.</param>
/// <param name="shift">The ammount and direction to move the specified entries.</param>
/// <returns>
/// Returns the resized and updated destination array.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">length;'length' argument must be greater then 0.</exception>
/// <remarks><p>To move entries to the left (towards 0) specify a negative shift value and a positive shift value to move entries to the right.</p>
/// <example>
/// <code>
/// var items = new[] { 0, 1, 2, 3, 4 };
/// items = items.Move(3, 2, -1);
/// </code>
/// Result should be { 0, 1, 3, 4, 4 }
/// </example></remarks>
public static T[] Move<T>(this T[] array, int index, int length, int shift)
{
if (length <= 0)
{
throw new ArgumentOutOfRangeException("length", "'length' argument must be greater then 0.");
}
if (shift > 0 && index + length + shift > array.Length - 1)
{
Array.Resize(ref array, array.Length + (index + length + shift - array.Length));
}
if (index + shift < 0)
{
length += index + shift;
index = -(index + shift);
}
length = Math.Min(array.Length - index, length);
if (length > 0)
{
Array.Copy(array, index, array, index + shift, length);
}
return array;
}
e86270ef-5f08-434f-b3bd-39dc58677b56|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Crops an array to a specified length.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="length">The length that the destination array will be set to.</param>
/// <returns>Returns the resized and updated destination array.</returns>
public static T[] Crop<T>(this T[] array, int length)
{
if (array == null)
{
return array;
}
Array.Resize(ref array, Math.Max(length, 0));
return array;
}
/// <summary>
/// Crops an array to a specified length.
/// </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 cropping begins at.</param>
/// <param name="length">The length that the destination array will be set to.</param>
/// <returns>
/// Returns the resized and updated destination array.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">length;'length' argument must be greater then 0.</exception>
public static T[] Crop<T>(this T[] array, int index, int length)
{
if (array == null)
{
return array;
}
if (length <= 0)
{
throw new ArgumentOutOfRangeException("length", "'length' argument must be greater then 0.");
}
if (index < 0 || index > array.Length - 1)
{
return array;
}
length = Math.Min(length, array.Length - index);
if (index > 0)
{
Array.Copy(array, index, array, 0, length);
}
Array.Resize(ref array, length);
return array;
}
c23d9534-31fa-47eb-a76d-632165d2935e|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Adds the specified source array to the end of the destination array.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="sourceArray">The source array that will be added to the end of the destination array.</param>
/// <returns>Returns the resized and updated destination array.</returns>
public static T[] Add<T>(this T[] array, T[] sourceArray)
{
if (array == null || sourceArray == null || sourceArray.Length == 0)
{
return array;
}
Array.Resize(ref array, array.Length + sourceArray.Length);
sourceArray.CopyTo(array, array.Length - sourceArray.Length);
return array;
}
/// <summary>
/// Adds a new extry to the end of the destination array.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="value">The item that will be added to the end of the destination array.</param>
/// <returns>Returns the resized and updated destination array.</returns>
public static T[] Add<T>(this T[] array, T value)
{
if (array == null)
{
return array;
}
Array.Resize(ref array, array.Length + 1);
array[array.Length - 1] = value;
return array;
}
82d87649-d126-4f44-a643-95930baeb75b|0|.0
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;
}
daa6947f-675b-4fdf-87d8-3b588cd2c2b0|0|.0
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;
}
1666aa75-988b-4cf9-98c5-b40f245b8404|0|.0
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);
}
254882e5-b438-4f50-9dcc-f1cf60e94a51|0|.0
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);
}
567c64d1-369f-4bcc-b834-300a19445fcd|0|.0
|
|