Ejemplo n.º 1
0
        public static void AddLast <T>([NotNull] this IList <T> list, [NotNull] T item)
        {
            if (list.IsReadOnly)
            {
                ExceptionThrower.ThrowArgumentReadOnlyCollectionException(nameof(list));
            }

            list.Insert(list.Count, item);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds if not exists.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="list">The list.</param>
        /// <param name="item">The value.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">list - List cannot be null. or value - Value cannot be null.</exception>
        /// <exception cref="ArgumentException">list - List cannot be null. or value - Value cannot be null.</exception>
        /// <exception cref="ArgumentNullException">list - List cannot be read-only.</exception>
        /// <exception cref="ArgumentException">list - List cannot be null. or value - Value cannot be null.</exception>
        public static bool AddIfNotExists <T>([NotNull] this ICollection <T> list, [NotNull] T item)
        {
            if (list.IsReadOnly)
            {
                ExceptionThrower.ThrowArgumentReadOnlyCollectionException(nameof(list));
            }

            if (list.Contains(item))
            {
                return(false);
            }

            list.Add(item);
            return(true);
        }