// SharpDevelop samples // Copyright (c) 2007, AlphaSierraPapa // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: // // - Redistributions of source code must retain the above copyright notice, this list // of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other materials // provided with the distribution. // // - Neither the name of the SharpDevelop team nor the names of its contributors may be used to // endorse or promote products derived from this software without specific prior written // permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; using System.Collections; using ICSharpCode.SharpDevelop; namespace ICSharpCode.NAnt { /// /// /// A collection that stores objects. /// /// /// [Serializable()] public class TaskCollection : CollectionBase { /// /// /// Initializes a new instance of . /// /// public TaskCollection() { } /// /// /// Initializes a new instance of based on another . /// /// /// /// A from which the contents are copied /// public TaskCollection(TaskCollection 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 TaskCollection(Task[] 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 Task this[int index] { get { return ((Task)(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(Task 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. /// /// /// None. /// /// public void AddRange(Task[] 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. /// /// /// None. /// /// public void AddRange(TaskCollection 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(Task 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. /// /// None. /// /// 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(Task[] 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(Task val) { return List.IndexOf(val); } /// /// Inserts a into the at the specified index. /// /// The zero-based index where should be inserted. /// The to insert. /// None. /// public void Insert(int index, Task val) { List.Insert(index, val); } /// /// Returns an enumerator that can iterate through /// the . /// /// None. /// public new TaskEnumerator GetEnumerator() { return new TaskEnumerator(this); } /// /// Removes a specific from the /// . /// /// The to remove from the . /// None. /// is not found in the Collection. public void Remove(Task val) { List.Remove(val); } public class TaskEnumerator : IEnumerator { IEnumerator baseEnumerator; IEnumerable temp; public TaskEnumerator(TaskCollection mappings) { this.temp = ((IEnumerable)(mappings)); this.baseEnumerator = temp.GetEnumerator(); } public Task Current { get { return ((Task)(baseEnumerator.Current)); } } object IEnumerator.Current { get { return baseEnumerator.Current; } } public bool MoveNext() { return baseEnumerator.MoveNext(); } bool IEnumerator.MoveNext() { return baseEnumerator.MoveNext(); } public void Reset() { baseEnumerator.Reset(); } void IEnumerator.Reset() { baseEnumerator.Reset(); } } } }