www.pudn.com > SharpUSBlib20041208.zip > DescriptorCollection.cs
// DescriptorCollection.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 DescriptorCollection : CollectionBase {
///
/// Initializes a new instance of .
///
public DescriptorCollection()
{
}
///
/// Initializes a new instance of based on another .
///
///
/// A from which the contents are copied
///
public DescriptorCollection(DescriptorCollection 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 DescriptorCollection(Descriptor[] 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 Descriptor this[int index] {
get {
return ((Descriptor)(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(Descriptor 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(Descriptor[] 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(DescriptorCollection 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(Descriptor 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(Descriptor[] 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(Descriptor 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, Descriptor val)
{
List.Insert(index, val);
}
///
/// Returns an enumerator that can iterate through the .
///
///
public new DescriptorEnumerator GetEnumerator()
{
return new DescriptorEnumerator(this);
}
///
/// Removes a specific from the .
///
/// The to remove from the .
/// is not found in the Collection.
public void Remove(Descriptor val)
{
List.Remove(val);
}
///
/// Enumerator that can iterate through a DescriptorCollection.
///
///
///
///
public class DescriptorEnumerator : IEnumerator
{
IEnumerator baseEnumerator;
IEnumerable temp;
///
/// Initializes a new instance of .
///
public DescriptorEnumerator(DescriptorCollection mappings)
{
this.temp = ((IEnumerable)(mappings));
this.baseEnumerator = temp.GetEnumerator();
}
///
/// Gets the current in the .
///
public Descriptor Current {
get {
return ((Descriptor)(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();
}
}
}
}