Exemple #1
0
        /// <summary>
        /// Requires the specified index to point inside the array or at the end.
        /// </summary>
        /// <exception cref="ArgumentNullException">Array is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Index is outside the array.</exception>
        public static void RequiresArrayInsertIndex <T>(IList <T> array, int index, string indexName)
        {
            Proclaim.NotEmpty(indexName);
            Proclaim.NotNull(array);

            if (index < 0 || index > array.Count)
            {
                throw new ArgumentOutOfRangeException(indexName);
            }
        }
Exemple #2
0
        /// <summary>
        /// Requires the array and all its items to be non-null.
        /// </summary>
        public static void RequiresNotNullItems <T>(IList <T> items, string name)
        {
            Proclaim.NotNull(name);
            RequiresNotNull(items, name);

            for (int i = 0; i < items.Count; i++)
            {
                if (items[i] == null)
                {
                    throw ExceptionFactory.CreateArgumentItemNullException(i, name);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Requires the range [offset, offset + count] to be a subset of [0, array.Count].
        /// </summary>
        /// <exception cref="ArgumentNullException">String is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Offset or count are out of range.</exception>
        public static void RequiresArrayRange(string str, int offset, int count, string offsetName, string countName)
        {
            Proclaim.NotEmpty(offsetName);
            Proclaim.NotEmpty(countName);
            Proclaim.NotNull(str);

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(countName);
            }
            if (offset < 0 || str.Length - offset < count)
            {
                throw new ArgumentOutOfRangeException(offsetName);
            }
        }
Exemple #4
0
        /// <summary>
        /// Requires the range [offset, offset + count] to be a subset of [0, array.Count].
        /// </summary>
        /// <exception cref="ArgumentNullException">Array is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Offset or count are out of range.</exception>
        public static void RequiresArrayRange <T>(IList <T> array, int offset, int count, string offsetName, string countName)
        {
            Proclaim.NotEmpty(offsetName);
            Proclaim.NotEmpty(countName);
            Proclaim.NotNull(array);

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(countName);
            }
            if (offset < 0 || array.Count - offset < count)
            {
                throw new ArgumentOutOfRangeException(offsetName);
            }
        }