Ejemplo n.º 1
0
        /// <summary>
        /// Finds the book by tag.
        /// </summary>
        /// <param name="tagPredicate">The tag predicate.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">tagPredicate</exception>
        /// <exception cref="System.ArgumentException">
        /// books count is 0
        /// or
        /// tagPredicate can't find such book.
        /// </exception>
        public Book FindBookByTag(IPredicate <Book> tagPredicate)
        {
            if (tagPredicate == null)
            {
                throw new ArgumentNullException($"{nameof(tagPredicate)} is null");
            }

            if (this.books.Count == 0)
            {
                throw new ArgumentException($"{nameof(books)} has 0 elements");
            }

            foreach (Book book in books)
            {
                if (tagPredicate.Find(book))
                {
                    return(book);
                }
            }

            throw new ArgumentException($"{nameof(tagPredicate)} can't find such book");
        }