www.pudn.com > SharpUSBlib20041208.zip > BusCollection.cs


// BusCollection.cs 
// Copyright (C) 2004 Mike Krueger 
//  
// This program is free software. It is dual licensed under GNU GPL and GNU LGPL. 
// See COPYING_GPL.txt and COPYING_LGPL.txt for details. 
// 
using System; 
using System.Collections; 
 
namespace ICSharpCode.USBlib 
{ 
	///  
	///   A collection that stores  objects. 
	///  
	[Serializable()] 
	public class BusCollection : CollectionBase { 
		 
		///  
		///   Initializes a new instance of . 
		///  
		public BusCollection() 
		{ 
		} 
		 
		///  
		///   Initializes a new instance of  based on another . 
		///  
		///  
		///   A  from which the contents are copied 
		///  
		public BusCollection(BusCollection val) 
		{ 
			this.AddRange(val); 
		} 
		 
		///  
		///   Initializes a new instance of  containing any array of  objects. 
		///  
		///  
		///       A array of  objects with which to intialize the collection 
		///  
		public BusCollection(Bus[] val) 
		{ 
			this.AddRange(val); 
		} 
		 
		///  
		///   Represents the entry at the specified index of the . 
		///  
		/// The zero-based index of the entry to locate in the collection. 
		/// The entry at the specified index of the collection. 
		///  is outside the valid range of indexes for the collection. 
		public Bus this[int index] { 
			get { 
				return ((Bus)(List[index])); 
			} 
			set { 
				List[index] = value; 
			} 
		} 
		 
		///  
		///   Adds a  with the specified value to the  
		///   . 
		///  
		/// The  to add. 
		/// The index at which the new element was inserted. 
		///  
		public int Add(Bus val) 
		{ 
			return List.Add(val); 
		} 
		 
		///  
		///   Copies the elements of an array to the end of the . 
		///  
		///  
		///    An array of type  containing the objects to add to the collection. 
		///  
		///  
		public void AddRange(Bus[] val) 
		{ 
			for (int i = 0; i < val.Length; i++) { 
				this.Add(val[i]); 
			} 
		} 
		 
		///  
		///   Adds the contents of another  to the end of the collection. 
		///  
		///  
		///    A  containing the objects to add to the collection. 
		///  
		///  
		public void AddRange(BusCollection val) 
		{ 
			for (int i = 0; i < val.Count; i++) 
			{ 
				this.Add(val[i]); 
			} 
		} 
		 
		///  
		///   Gets a value indicating whether the  
		///     contains the specified . 
		///  
		/// The  to locate. 
		///  
		///  if the  is contained in the collection;  
		///   otherwise, . 
		///  
		///  
		public bool Contains(Bus val) 
		{ 
			return List.Contains(val); 
		} 
		 
		///  
		///   Copies the  values to a one-dimensional  instance at the  
		///    specified index. 
		///  
		/// The one-dimensional  that is the destination of the values copied from . 
		/// The index in  where copying begins. 
		///  
		///    is multidimensional. 
		///   -or- 
		///   The number of elements in the  is greater than 
		///         the available space between  and the end of 
		///         . 
		///  
		///  is .  
		///  is less than 's lowbound.  
		///  
		public void CopyTo(Bus[] array, int index) 
		{ 
			List.CopyTo(array, index); 
		} 
		 
		///  
		///    Returns the index of a  in  
		///       the . 
		///  
		/// The  to locate. 
		///  
		///   The index of the  of  in the  
		///   , if found; otherwise, -1. 
		///  
		///  
		public int IndexOf(Bus val) 
		{ 
			return List.IndexOf(val); 
		} 
		 
		///  
		///   Inserts a  into the  at the specified index. 
		///  
		/// The zero-based index where  should be inserted. 
		/// The  to insert. 
		///  
		public void Insert(int index, Bus val) 
		{ 
			List.Insert(index, val); 
		} 
		 
		///  
		///  Returns an enumerator that can iterate through the . 
		///  
		///  
		public new BusEnumerator GetEnumerator() 
		{ 
			return new BusEnumerator(this); 
		} 
		 
		///  
		///   Removes a specific  from the . 
		///  
		/// The  to remove from the . 
		///  is not found in the Collection. 
		public void Remove(Bus val) 
		{ 
			List.Remove(val); 
		} 
		 
		///  
		///   Enumerator that can iterate through a BusCollection. 
		///  
		///  
		///  
		///  
		public class BusEnumerator : IEnumerator 
		{ 
			IEnumerator baseEnumerator; 
			IEnumerable temp; 
			 
			///  
			///   Initializes a new instance of . 
			///  
			public BusEnumerator(BusCollection mappings) 
			{ 
				this.temp = ((IEnumerable)(mappings)); 
				this.baseEnumerator = temp.GetEnumerator(); 
			} 
			 
			///  
			///   Gets the current  in the . 
			///  
			public Bus Current { 
				get { 
					return ((Bus)(baseEnumerator.Current)); 
				} 
			} 
			 
			object IEnumerator.Current { 
				get { 
					return baseEnumerator.Current; 
				} 
			} 
			 
			///  
			///   Advances the enumerator to the next  of the . 
			///  
			public bool MoveNext() 
			{ 
				return baseEnumerator.MoveNext(); 
			} 
			 
			///  
			///   Sets the enumerator to its initial position, which is before the first element in the . 
			///  
			public void Reset() 
			{ 
				baseEnumerator.Reset(); 
			} 
		} 
	} 
}