///
/// Expands the array by the given size.
///
/// the source array. can be null. All values will be copied to the new array.
/// Increment size of the new array
/// types of the new array
///
/// if arrayItemType parameter is null.
/// if size parameter is less or equal to zero
/// if type of source array is not convertable to arrayItemType
public static Array ExpandArray(Array array, int size, Type arrayItemType)
{
if(arrayItemType == null)
throw new ArgumentNullException("arrayItemType");
if(size <= 0)
throw new ArgumentOutOfRangeException("size", size, "Size must be greater then 0!");
Array me = Array.CreateInstance(arrayItemType, array == null ? size : array.Length + size);
if(array != null && array.Length > 0)
{
for(int i = 0; i < array.Length; i++)
{
object val = array.GetValue(i);
me.SetValue(Convert.ChangeType(val, arrayItemType) , i);
}
}
return me;
}
|