Exemple #1
0
        /// <overloads>
        /// <param name="message">Message if the condition isn't met</param>
        /// </overloads>
        public static void Requires(bool condition, string name, string message)
        {
            Proclaim.NotEmpty(name);

            if (!condition)
            {
                throw new ArgumentException(message, name);
            }
        }
Exemple #2
0
        /// <summary>
        /// Requires that a value not be <c>null</c>.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="name"></param>
        /// <exception cref="ArgumentNullException">Value is <c>null</c>.</exception>
        public static void RequiresNotNull <T>(T value, string name) where T : class
        {
            Proclaim.NotEmpty(name);

            if (value == null)
            {
                throw new ArgumentNullException(name);
            }
        }
Exemple #3
0
        /// <overloads>
        /// <param name="name">Name of the requirement, this should be something unique to make it easy to find.</param>
        /// </overloads>
        public static void Requires(bool condition, string name)
        {
            Proclaim.NotEmpty(name);

            if (!condition)
            {
                throw new ArgumentException("Invalid parameter value.", name);
            }
        }
Exemple #4
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 #5
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 #6
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 #7
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);
            }
        }