⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchcriteriacollection.cs

📁 SharpNuke源代码
💻 CS
字号:
using System;
using System.Collections;

//
// DotNetNuke -  http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//


namespace DotNetNuke.Services.Search
{
	
	/// -----------------------------------------------------------------------------
	/// Namespace:  DotNetNuke.Services.Search
	/// Project:    DotNetNuke.Search.DataStore
	/// Class:      SearchCriteria
	/// -----------------------------------------------------------------------------
	/// <summary>
	/// Represents a collection of <see cref="SearchCriteria">SearchCriteria</see> objects.
	/// </summary>
	/// <returns></returns>
	/// <remarks>
	/// </remarks>
	/// <history>
	///		[cnurse]	11/15/2004	documented
	/// </history>
	/// -----------------------------------------------------------------------------
	public class SearchCriteriaCollection : CollectionBase
	{
		
		#region "Constructors"
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class.
		/// </summary>
		public SearchCriteriaCollection() 
		{
		}
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class containing the elements of the specified source collection.
		/// </summary>
		/// <param name="value">A <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> with which to initialize the collection.</param>
		public SearchCriteriaCollection(SearchCriteriaCollection value) 
		{
			AddRange(value);
		}
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class containing the specified array of <see cref="SearchCriteria">SearchCriteria</see> objects.
		/// </summary>
		/// <param name="value">An array of <see cref="SearchCriteria">SearchCriteria</see> objects with which to initialize the collection. </param>
		public SearchCriteriaCollection(SearchCriteria[] value) 
		{
			AddRange(value);
		}
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class containing the elements of the specified source collection.
		/// </summary>
		/// <param name="value">A criteria string with which to initialize the collection</param>
		public SearchCriteriaCollection(string value) 
		{
			
			// split search criteria into words
			string[] words = value.Split(' ');
			// Add all criteria without modifiers
			// Add all mandatory criteria
			// Add all excluded criteria
			foreach (string word in words)
			{
				SearchCriteria criterion = new SearchCriteria();
				
				criterion.MustInclude = word.StartsWith("+");
				criterion.MustExclude = word.StartsWith("-");
				if (criterion.MustExclude || criterion.MustInclude)
					criterion.Criteria = word.Remove(0,1);
				else
					criterion.Criteria = word;
				Add(criterion);
			}
		}
		
		
		#endregion
		
		#region "Properties"
		
		/// <summary>
		/// Gets the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> at the specified index in the collection.
		/// <para>
		/// In VB.Net, this property is the indexer for the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class.
		/// </para>
		/// </summary>
		public SearchCriteria this[int index]
		{
			get { return ((SearchCriteria) List[index]); }
			set { List[index] = value; }
		}
		
		#endregion
		
		#region "Public Methods"
		
		/// <summary>
		/// Add an element of the specified <see cref="SearchCriteria">SearchCriteria</see> to the end of the collection.
		/// </summary>
		/// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to add to the collection.</param>
		public int Add(SearchCriteria value)
		{
			return List.Add(value);
		} //Add
		
		/// <summary>
		/// Gets the index in the collection of the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>, if it exists in the collection.
		/// </summary>
		/// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to locate in the collection.</param>
		/// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
		public int IndexOf(SearchCriteria value)
		{
			return List.IndexOf(value);
		} //IndexOf
		
		/// <summary>
		/// Add an element of the specified <see cref="SearchCriteria">SearchCriteria</see> to the collection at the designated index.
		/// </summary>
		/// <param name="index">An <see cref="system.int32">Integer</see> to indicate the location to add the object to the collection.</param>
		/// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to add to the collection.</param>
		public void Insert (int index, SearchCriteria value)
		{
			List.Insert(index, value);
		} //Insert
		
		/// <summary>
		/// Remove the specified object of type <see cref="SearchCriteria">SearchCriteria</see> from the collection.
		/// </summary>
		/// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to remove to the collection.</param>
		public void Remove (SearchCriteria value)
		{
			List.Remove(value);
		} //Remove
		
		/// <summary>
		/// Gets a value indicating whether the collection contains the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>.
		/// </summary>
		/// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to search for in the collection.</param>
		/// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
		public bool Contains(SearchCriteria value)
		{
			// If value is not of type SearchCriteria, this will return false.
			return List.Contains(value);
		} //Contains
		
		/// <summary>
		/// Copies the elements of the specified <see cref="SearchCriteria">SearchCriteria</see> array to the end of the collection.
		/// </summary>
		/// <param name="value">An array of type <see cref="SearchCriteria">SearchCriteria</see> containing the objects to add to the collection.</param>
		public void AddRange (SearchCriteria[] value)
		{
			foreach (SearchCriteria searchCriteria in value)
			{
				Add(searchCriteria);
			}
		}
		
		/// <summary>
		/// Adds the contents of another <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to the end of the collection.
		/// </summary>
		/// <param name="value">A <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> containing the objects to add to the collection. </param>
		public void AddRange (SearchCriteriaCollection value)
		{
			foreach (SearchCriteria searchCriteria in value)
			{
				Add(searchCriteria);
			}
		}
		
		/// <summary>
		/// Copies the collection objects to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index.
		/// </summary>
		/// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param>
		/// <param name="index">The index of the array at which to begin inserting.</param>
		public void CopyTo (SearchCriteria[] array, int index)
		{
			List.CopyTo(array, index);
		}
		
		/// <summary>
		/// Creates a one-dimensional <see cref="T:System.Array">Array</see> instance containing the collection items.
		/// </summary>
		/// <returns>Array of type SearchCriteria</returns>
		public SearchCriteria[] ToArray()
		{
			SearchCriteria[] arr = new SearchCriteria[List.Count];
			CopyTo(arr, 0);
			
			return arr;
		}
		
		#endregion
		
	}
	
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -