/// <summary> /// This methods allocates a mutable array and copies all the colletion elements to it /// </summary> /// <param name="collection">Collection to copy elements from</param> /// <returns>Array</returns> private static T[] AllocInternalArray(ICollection <T> collection) { T[] ret = ImmutableArrayInternal <T> .AllocInternalArray(collection.Count); collection.CopyTo(ret, 0); return(ret); }
/// <summary> /// This method allocates a copy of the specified array /// </summary> /// <param name="sourceIndex">Index to start the copy</param> /// <param name="data">Array of data to be copied</param> /// <param name="length">Length od data to topy</param> /// <returns>A partial/complete clone of the specified array</returns> private static T[] AllocInternalArray(int sourceIndex, T[] data, int length) { if (length == 0) { return(EmptyArray); } T[] ret = ImmutableArrayInternal <T> .AllocInternalArray(length); Array.Copy(data, sourceIndex, ret, sourceIndex, length); return(ret); }
public ImmutableArrayInternal(int sourceIndex, T[] data, int length) { if (sourceIndex < 0) { throw new IndexOutOfRangeException("Index cannot be less than zero"); } if (data == null) { throw new ArgumentNullException("data", "Array cannot be null"); } if ((sourceIndex + length) > data.Length) { throw new ArgumentOutOfRangeException("The sourceIndex and length specified overcome the source ByteArray length"); } _offset = 0; _data = ImmutableArrayInternal <T> .AllocInternalArray(sourceIndex, data, length); _length = length; }