public static int Copy <T>(T[] source, int sourceOffset, MarshalArrayBase destination, int destOffset, int count)
        {
            if (sourceOffset < 0 || destOffset < 0 || count < 0)
            {
                throw new ArgumentException("sourceOffset < 0 or destOffset < 0 or count < 0");
            }

            if (source.Length - sourceOffset < count)
            {
                count = source.Length - sourceOffset;
            }

            if (destination.Length - destOffset < count)
            {
                count = destination.Length - destOffset;
            }

            int srcIndex = sourceOffset;
            int dstIndex = destOffset;
            int srcEnd   = sourceOffset + count;

            while (srcIndex < srcEnd)
            {
                destination.SetValue <T>(dstIndex, source[srcIndex]);
                ++dstIndex;
                ++srcIndex;
            }
            return(count);
        }
        public static int LastIndexOf <T>(MarshalArrayBase source, T item, int beginIndex, int count)
        {
            if (beginIndex < 0 || count < 0)
            {
                throw new ArgumentException("beginIndex < 0 or count < 0");
            }

            if (beginIndex >= source.Length)
            {
                beginIndex = source.Length - 1;
            }

            if (beginIndex + 1 < count)
            {
                count = beginIndex + 1;
            }

            int end = beginIndex - count;
            int i   = beginIndex;

            while (i > end)
            {
                if (source.GetValue <T>(i).Equals(item))
                {
                    return(i);
                }
                --i;
            }

            return(-1);
        }
 public void CopyTo(int index, MarshalArray <T> array, int arrayIndex, int count)
 {
     if (this.m_size - index < count)
     {
         ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
     }
     MarshalArrayBase.Copy(this.m_items, index, array, arrayIndex, count);
 }
 public int IndexOf(T item, int index)
 {
     if (index > this.m_size)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
     }
     return(MarshalArrayBase.IndexOf <T>(this.m_items, item, index, this.m_size - index));
 }
 public void RemoveAt(int index)
 {
     if ((uint)index >= (uint)this.m_size)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException();
     }
     --this.m_size;
     if (index < this.m_size)
     {
         MarshalArrayBase.Copy(this.m_items, index + 1, this.m_items, index, this.m_size - index);
     }
     this.m_items[this.m_size] = default(T);
     ++this.m_version;
 }
 public int LastIndexOf(T item, int index, int count)
 {
     if (this.m_size == 0)
     {
         return(-1);
     }
     if (index < 0 || count < 0)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException(index < 0 ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
     }
     if (index >= this.m_size || count > index + 1)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException(index >= this.m_size ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
     }
     return(MarshalArrayBase.LastIndexOf <T>(this.m_items, item, index, count));
 }
        public void InsertRange(int index, IEnumerable <T> collection)
        {
            if (collection == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
            }
            if ((uint)index > (uint)this.m_size)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
            }
            ICollection <T> objs = collection as ICollection <T>;

            if (objs != null)
            {
                int count = objs.Count;
                if (count > 0)
                {
                    this.EnsureCapacity(this.m_size + count);
                    if (index < this.m_size)
                    {
                        MarshalArrayBase.Copy(this.m_items, index, this.m_items, index + count, this.m_size - index);
                    }
                    if (this == objs)
                    {
                        MarshalArrayBase.Copy(this.m_items, 0, this.m_items, index, index);
                        MarshalArrayBase.Copy(this.m_items, index + count, this.m_items, index * 2, this.m_size - index);
                    }
                    else
                    {
                        T[] array = new T[count];
                        objs.CopyTo(array, 0);
                        MarshalArrayBase.Copy <T>(array, 0, m_items, index, count);
                    }
                    this.m_size += count;
                }
            }
            else
            {
                foreach (T obj in collection)
                {
                    this.Insert(index++, obj);
                }
            }
            ++this.m_version;
        }
 public void Insert(int index, T item)
 {
     if ((uint)index > (uint)this.m_size)
     {
         ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
     }
     if (this.m_size == this.m_items.Length)
     {
         this.EnsureCapacity(this.m_size + 1);
     }
     if (index < this.m_size)
     {
         MarshalArrayBase.Copy(this.m_items, index, this.m_items, index + 1, this.m_size - index);
     }
     this.m_items[index] = item;
     ++this.m_size;
     ++this.m_version;
 }
        public MarshalList <T> GetRange(int index, int count)
        {
            if (index < 0 || count < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(
                    index < 0 ? ExceptionArgument.index : ExceptionArgument.count,
                    ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
            }

            if (this.m_size - index < count)
            {
                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
            }

            MarshalList <T> objList = new MarshalList <T>(count);

            MarshalArrayBase.Copy(this.m_items, index, objList.m_items, 0, count);
            objList.m_size = count;
            return(objList);
        }
        public unsafe static int Copy(MarshalArrayBase source, int sourceOffset, MarshalArrayBase destination, int destOffset, int count)
        {
            if (sourceOffset < 0 || destOffset < 0 || count < 0)
            {
                throw new ArgumentException("sourceOffset < 0 or destOffset < 0 or count < 0");
            }

            if (source.Length - sourceOffset < count)
            {
                count = source.Length - sourceOffset;
            }

            if (destination.Length - destOffset < count)
            {
                count = destination.Length - destOffset;
            }


            return(CopyBytes(source.Ptr, source.m_elementSize * sourceOffset,
                             destination.Ptr, destination.m_elementSize * destOffset,
                             source.m_elementSize * count));
        }
Beispiel #11
0
        public void RemoveRange(int index, int count)
        {
            if (index < 0 || count < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(index < 0 ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (this.m_size - index < count)
            {
                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
            }
            if (count <= 0)
            {
                return;
            }
            this.m_size -= count;
            if (index < this.m_size)
            {
                MarshalArrayBase.Copy(this.m_items, index + count, this.m_items, index, this.m_size - index);
            }

            //MarshalArrayBase.Clear(this.m_items, this.m_size, count);

            ++this.m_version;
        }
Beispiel #12
0
 public int IndexOf(T item)
 {
     return(MarshalArrayBase.IndexOf <T>(this.m_items, item, 0, this.m_size));
 }
Beispiel #13
0
 public void CopyTo(MarshalArray <T> array, int arrayIndex)
 {
     MarshalArrayBase.Copy(this.m_items, 0, array, arrayIndex, this.m_size);
 }
Beispiel #14
0
 public void CopyTo(Array array, int index)
 {
     MarshalArrayBase.Copy(this.m_items, 0, (T[])array, index, this.m_size);
 }
Beispiel #15
0
 public T[] ToArray()
 {
     T[] objArray = new T[this.m_size];
     MarshalArrayBase.Copy(this.m_items, 0, objArray, 0, this.m_size);
     return(objArray);
 }