Esempio n. 1
0
        internal void CopyTo(Array array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (array.Rank != 1)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
            }
            int lowerBound = array.GetLowerBound(0);
            int num        = this.Count();
            int length     = array.GetLength(0);

            if (arrayIndex < lowerBound)
            {
                throw new ArgumentOutOfRangeException("arrayIndex");
            }
            if (num > length - (arrayIndex - lowerBound))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InsufficientSpaceToCopyCollection"));
            }
            if (arrayIndex - lowerBound > length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds"));
            }
            IBindableVector bindableVector = JitHelpers.UnsafeCast <IBindableVector>((object)this);

            for (uint index = 0; (long)index < (long)num; ++index)
            {
                array.SetValue(bindableVector.GetAt(index), (long)index + (long)arrayIndex);
            }
        }
        // Token: 0x06006477 RID: 25719 RVA: 0x00154B9C File Offset: 0x00152D9C
        object IBindableVector.GetAt(uint index)
        {
            IBindableVector ibindableVectorNoThrow = this.GetIBindableVectorNoThrow();

            if (ibindableVectorNoThrow != null)
            {
                return(ibindableVectorNoThrow.GetAt(index));
            }
            return(this.GetVectorOfT().GetAt(index));
        }
        internal void CopyTo(Array array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            // ICollection expects the destination array to be single-dimensional.
            if (array.Rank != 1)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
            }

            int destLB = array.GetLowerBound(0);

            int srcLen  = Count();
            int destLen = array.GetLength(0);

            if (arrayIndex < destLB)
            {
                throw new ArgumentOutOfRangeException("arrayIndex");
            }

            // Does the dimension in question have sufficient space to copy the expected number of entries?
            // We perform this check before valid index check to ensure the exception message is in sync with
            // the following snippet that uses regular framework code:
            //
            // ArrayList list = new ArrayList();
            // list.Add(1);
            // Array items = Array.CreateInstance(typeof(object), new int[] { 1 }, new int[] { -1 });
            // list.CopyTo(items, 0);

            if (srcLen > (destLen - (arrayIndex - destLB)))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InsufficientSpaceToCopyCollection"));
            }

            if (arrayIndex - destLB > destLen)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds"));
            }

            // We need to verify the index as we;
            IBindableVector _this = JitHelpers.UnsafeCast <IBindableVector>(this);

            for (uint i = 0; i < srcLen; i++)
            {
                array.SetValue(_this.GetAt(i), i + arrayIndex);
            }
        }
Esempio n. 4
0
        //
        // IBindableVector implementation (forwards to IBindableVector / IVector<T>)
        //
        object IBindableVector.GetAt(uint index)
        {
            IBindableVector bindableVector = GetIBindableVectorNoThrow();

            if (bindableVector != null)
            {
                // IBindableVector -> IBindableVector
                return(bindableVector.GetAt(index));
            }
            else
            {
                // IBindableVector -> IVector<T>
                return(GetVectorOfT().GetAt(index));
            }
        }
Esempio n. 5
0
 private static object GetAt(IBindableVector _this, uint index)
 {
     try
     {
         return(_this.GetAt(index));
     }
     catch (Exception ex)
     {
         if (-2147483637 == ex._HResult)
         {
             throw new ArgumentOutOfRangeException("index");
         }
         throw;
     }
 }
        // Helpers:

        private static object?GetAt(IBindableVector _this, uint index)
        {
            try
            {
                return(_this.GetAt(index));

                // We delegate bounds checking to the underlying collection and if it detected a fault,
                // we translate it to the right exception:
            }
            catch (Exception ex)
            {
                if (HResults.E_BOUNDS == ex.HResult)
                {
                    throw new ArgumentOutOfRangeException(nameof(index));
                }

                throw;
            }
        }
        // Helpers:

        private static object GetAt(IBindableVector _this, uint index)
        {
            try
            {
                return _this.GetAt(index);

                // We delegate bounds checking to the underlying collection and if it detected a fault,
                // we translate it to the right exception:
            }
            catch (Exception ex)
            {
                if (__HResults.E_BOUNDS == ex._HResult)
                    throw new ArgumentOutOfRangeException("index");

                throw;
            }
        }