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

📄 opmlitemcollection.cs

📁 基于.Net环境下c#实现的国人自己的Blog平台,基于.Text的核心技术,但做了汉化以及改写了一部分的核心代码,值得研究学习
💻 CS
📖 第 1 页 / 共 4 页
字号:
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.Insert"/> for details.</remarks>
		public virtual void Insert(int index, OpmlItem value)
		{
			if (index < 0)
				throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative.");
			if (index > this._count)
				throw new ArgumentOutOfRangeException("index", index, "Argument cannot exceed Count.");

			if (this._count == this._array.Length)
				EnsureCapacity(this._count + 1);

			++this._version;
			if (index < this._count)
				Array.Copy(this._array, index, this._array, index + 1, this._count - index);

			this._array[index] = value;
			++this._count;
		}

		/// <summary>
		/// Inserts an element into the <see cref="OpmlItemCollection"/> at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index at which <paramref name="value"/> 
		/// should be inserted.</param>
		/// <param name="value">The object to insert into the <see cref="OpmlItemCollection"/>.
		/// This argument must be compatible with <see cref="OpmlItem"/>.
		/// This argument can be a null reference.
		/// </param>    
		/// <exception cref="ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero.</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> is greater than <see cref="Count"/>.</para>
		/// </exception>
		/// <exception cref="InvalidCastException"><paramref name="value"/>
		/// is not compatible with <see cref="OpmlItem"/>.</exception>    
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="OpmlItemCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.Insert"/> for details.</remarks>
		void IList.Insert(int index, object value)
		{
			Insert(index, (OpmlItem) value);
		}

		#endregion

		#region ReadOnly

		/// <summary>
		/// Returns a read-only wrapper for the specified <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <param name="collection">The <see cref="OpmlItemCollection"/> to wrap.</param>    
		/// <returns>A read-only wrapper around <paramref name="collection"/>.</returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>    
		/// <remarks>Please refer to <see cref="ArrayList.ReadOnly"/> for details.</remarks>
		public static OpmlItemCollection ReadOnly(OpmlItemCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			return new ReadOnlyList(collection);
		}

		#endregion

		#region Remove

		/// <summary>
		/// Removes the first occurrence of the specified <see cref="OpmlItem"/>
		/// from the <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <param name="value">The <see cref="OpmlItem"/> object
		/// to remove from the <see cref="OpmlItemCollection"/>.
		/// This argument can be a null reference.
		/// </param>    
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="OpmlItemCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks>
		public virtual void Remove(OpmlItem value)
		{
			int index = IndexOf(value);
			if (index >= 0)
				RemoveAt(index);
		}

		/// <summary>
		/// Removes the first occurrence of the specified <see cref="Object"/>
		/// from the <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <param name="value">The object to remove from the <see cref="OpmlItemCollection"/>.
		/// This argument must be compatible with <see cref="OpmlItem"/>.
		/// This argument can be a null reference.
		/// </param>    
		/// <exception cref="InvalidCastException"><paramref name="value"/>
		/// is not compatible with <see cref="OpmlItem"/>.</exception>    
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="OpmlItemCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks>
		void IList.Remove(object value)
		{
			Remove((OpmlItem) value);
		}

		#endregion

		#region RemoveAt

		/// <summary>
		/// Removes the element at the specified index of the <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <param name="index">The zero-based index of the element to remove.</param>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero.</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
		/// </exception>
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="OpmlItemCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.RemoveAt"/> for details.</remarks>
		public virtual void RemoveAt(int index)
		{
			ValidateIndex(index);

			++this._version;
			if (index < --this._count)
				Array.Copy(this._array, index + 1, this._array, index, this._count - index);

			this._array[this._count] = null;
		}

		#endregion

		#region RemoveRange

		/// <summary>
		/// Removes a range of elements from the <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <param name="index">The zero-based starting index of the range
		/// of elements to remove.</param>
		/// <param name="count">The number of elements to remove.</param>
		/// <exception cref="ArgumentException">
		/// <paramref name="index"/> and <paramref name="count"/> do not denote a
		/// valid range of elements in the <see cref="OpmlItemCollection"/>.</exception>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero.</para>
		/// <para>-or-</para>
		/// <para><paramref name="count"/> is less than zero.</para>
		/// </exception>
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="OpmlItemCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.RemoveRange"/> for details.</remarks>
		public virtual void RemoveRange(int index, int count)
		{
			if (index < 0)
				throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative.");
			if (count < 0)
				throw new ArgumentOutOfRangeException("count", count, "Argument cannot be negative.");
			if (index + count > this._count)
				throw new ArgumentException("Arguments denote invalid range of elements.");

			if (count == 0)
				return;

			++this._version;
			this._count -= count;

			if (index < this._count)
				Array.Copy(this._array, index + count, this._array, index, this._count - index);

			Array.Clear(this._array, this._count, count);
		}

		#endregion

		#region Sort

		/// <summary>
		/// Sorts the elements in the entire <see cref="OpmlItemCollection"/>
		/// using the <see cref="IComparable"/> implementation of each element.
		/// </summary>
		/// <exception cref="NotSupportedException">
		/// The <see cref="OpmlItemCollection"/> is read-only.</exception>
		/// <remarks>Please refer to <see cref="ArrayList.Sort"/> for details.</remarks>
		public virtual void Sort()
		{
			if (this._count <= 1)
				return;
			++this._version;
			Array.Sort(this._array, 0, this._count);
		}

		#endregion

		#region Synchronized

		/// <summary>
		/// Returns a synchronized (thread-safe) wrapper 
		/// for the specified <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <param name="collection">The <see cref="OpmlItemCollection"/> to synchronize.</param>    
		/// <returns>
		/// A synchronized (thread-safe) wrapper around <paramref name="collection"/>.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="collection"/> is a null reference.</exception>    
		/// <remarks>Please refer to <see cref="ArrayList.Synchronized"/> for details.</remarks>
		public static OpmlItemCollection Synchronized(OpmlItemCollection collection)
		{
			if (collection == null)
				throw new ArgumentNullException("collection");

			return new SyncList(collection);
		}

		#endregion

		#region ToArray

		/// <summary>
		/// Copies the elements of the <see cref="OpmlItemCollection"/> to a new
		/// <see cref="Array"/> of <see cref="OpmlItem"/> elements.
		/// </summary>
		/// <returns>A one-dimensional <see cref="Array"/> of <see cref="OpmlItem"/> 
		/// elements containing copies of the elements of the <see cref="OpmlItemCollection"/>.</returns>
		/// <remarks>Please refer to <see cref="ArrayList.ToArray"/> for details.</remarks>
		public virtual OpmlItem[] ToArray()
		{
			OpmlItem[] array = new OpmlItem[this._count];
			Array.Copy(this._array, array, this._count);
			return array;
		}

		#endregion

		#region TrimToSize

		/// <summary>
		/// Sets the capacity to the actual number of elements in the <see cref="OpmlItemCollection"/>.
		/// </summary>
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="OpmlItemCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>OpmlItemCollection</b> has a fixed size.</para></exception>    
		/// <remarks>Please refer to <see cref="ArrayList.TrimToSize"/> for details.</remarks>
		public virtual void TrimToSize()
		{
			Capacity = this._count;
		}

		#endregion

		#endregion

		#region Private Methods

		private void CheckEnumIndex(int index)
		{
			if (index < 0 || index >= this._count)
				throw new InvalidOperationException("Enumerator is not on a collection element.");
		}

		private void CheckEnumVersion(int version)
		{
			if (version != this._version)
				throw new InvalidOperationException("Enumerator invalidated by modification to collection.");
		}

		private void CheckTargetArray(Array array, int arrayIndex)
		{
			if (array == null)
				throw new ArgumentNullException("array");
			if (array.Rank > 1)
				throw new ArgumentException("Argument cannot be multidimensional.", "array");
			if (arrayIndex < 0)
				throw new ArgumentOutOfRangeException("arrayIndex", arrayIndex, "Argument cannot be negative.");
			if (arrayIndex >= array.Length)
				throw new ArgumentException("Argument must be less than array length.", "arrayIndex");
			if (this._count > array.Length - arrayIndex)
				throw new ArgumentException("Argument section must be large enough for collection.", "array");
		}

		private void EnsureCapacity(int minimum)
		{
			int newCapacity = (this._array.Length == 0 ?
				_defaultCapacity : this._array.Length*2);

			if (newCapacity < minimum)
				newCapacity = minimum;
			Capacity = newCapacity;
		}

		private void ValidateIndex(int index)
		{
			if (index < 0)
				throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative.");
			if (index >= this._count)
				throw new ArgumentOutOfRangeException("index", index, "Argument must be less than Count.");
		}

		#endregion

		#region Class Enumerator

		[Serializable]
		private sealed class Enumerator : IOpmlItemEnumerator, IEnumerator
		{

			private readonly OpmlItemCollection _collection;
			private readonly int _version;
			private int _index;

			internal Enumerator(OpmlItemCollection collection)
			{
				this._collection = collection;
				this._version = collection._version;
				this._index = -1;
			}

			public OpmlItem Current
			{
				get
				{
					this._collection.CheckEnumIndex(this._index);
					return this._collection[this._index];
				}
			}

			object IEnumerator.Current
			{
				get { return Current; }
			}

			public bool MoveNext()
			{
				this._collection.CheckEnumVersion(this._version);
				return (++this._index < this._collection.Count);
			}

			public void Reset()
			{
				this._collection.CheckEnumVersion(this._version);
				this._index = -1;

⌨️ 快捷键说明

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