/// <summary>
        /// Initializes a new instance of the <see cref="GalleryObjectSearcher" /> class.
        /// </summary>
        /// <param name="searchOptions">The search options.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="searchOptions" /> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when one or more properties of the <paramref name="searchOptions" /> parameter is invalid.</exception>
        /// <exception cref="Events.CustomExceptions.InvalidGalleryException">Thrown when the gallery ID specified in the <paramref name="searchOptions" />
        /// parameter is invalid.</exception>
        public GalleryObjectSearcher(GalleryObjectSearchOptions searchOptions)
        {
            Validate(searchOptions);

            SearchOptions = searchOptions;

            if (SearchOptions.Roles == null)
            {
                SearchOptions.Roles = new GalleryServerRoleCollection();
            }
        }
        /// <summary>
        /// Validates the specified search options. Throws an exception if not valid.
        /// </summary>
        /// <param name="searchOptions">The search options.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="searchOptions" /> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when one or more properties of the <paramref name="searchOptions" /> parameter is invalid.</exception>
        /// <exception cref="Events.CustomExceptions.InvalidGalleryException">Thrown when the gallery ID specified in the <paramref name="searchOptions" />
        /// parameter is invalid.</exception>
        private static void Validate(GalleryObjectSearchOptions searchOptions)
        {
            if (searchOptions == null)
            {
                throw new ArgumentNullException("searchOptions");
            }

            if (searchOptions.SearchType == GalleryObjectSearchType.NotSpecified)
            {
                throw new ArgumentException("The SearchType property of the searchOptions parameter must be set to a valid search type.");
            }

            if (searchOptions.IsUserAuthenticated && searchOptions.Roles == null)
            {
                throw new ArgumentException("The Roles property of the searchOptions parameter must be specified when IsUserAuthenticated is true.");
            }

            if (searchOptions.GalleryId < 0) // v3+ galleries start at 1, but galleries from earlier versions begin at 0
            {
                throw new ArgumentException("Invalid gallery ID. The GalleryId property of the searchOptions parameter must refer to a valid gallery.");
            }

            if ((searchOptions.SearchType == GalleryObjectSearchType.SearchByTag || searchOptions.SearchType == GalleryObjectSearchType.SearchByPeople) && (searchOptions.Tags == null || searchOptions.Tags.Length == 0))
            {
                throw new ArgumentException("The Tags property of the searchOptions parameter must be specified when SearchType is SearchByTag or SearchByPeople.");
            }

            if (searchOptions.SearchType == GalleryObjectSearchType.SearchByRating && (searchOptions.SearchTerms == null || searchOptions.SearchTerms.Length != 1))
            {
                throw new ArgumentException("The SearchTerms property of the searchOptions parameter must contain a single string matching one of these values: highest, lowest, none, or a number from 0 to 5.");
            }

            // This throws an exception when gallery ID doesn't exist or is the template gallery.
            Factory.LoadGallery(searchOptions.GalleryId);

            if (searchOptions.Filter == GalleryObjectType.Unknown || searchOptions.Filter == GalleryObjectType.NotSpecified)
            {
                throw new ArgumentException(String.Format("The Filter property of the searchOptions parameter cannot be GalleryObjectType.{0}.", searchOptions.Filter));
            }
        }