/// <summary> /// Initializes a new instance of the <see cref="TagSearcher" /> 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> public TagSearcher(TagSearchOptions 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> private static void Validate(TagSearchOptions searchOptions) { if (searchOptions == null) { throw new ArgumentNullException("searchOptions"); } if (searchOptions.SearchType == TagSearchType.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."); } }