// NAnt - A .NET build tool
// Copyright (C) 2001-2003 Gerry Shaw
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Gerry Shaw (gerry_shaw@yahoo.com)
// Gert Driesen (gert.driesen@ardatis.com)
using System;
using System.Collections;
namespace NAnt.Core {
///
/// Contains a strongly typed collection of objects.
///
[Serializable]
public class TaskBuilderCollection : CollectionBase {
#region Public Instance Constructors
///
/// Initializes a new instance of the class.
///
public TaskBuilderCollection() {
}
///
/// Initializes a new instance of the class
/// with the specified instance.
///
public TaskBuilderCollection(TaskBuilderCollection value) {
AddRange(value);
}
///
/// Initializes a new instance of the class
/// with the specified array of instances.
///
public TaskBuilderCollection(TaskBuilder[] value) {
AddRange(value);
}
#endregion Public Instance Constructors
#region Public Instance Properties
///
/// Gets or sets the element at the specified index.
///
/// The zero-based index of the element to get or set.
[System.Runtime.CompilerServices.IndexerName("Item")]
public TaskBuilder this[int index] {
get {return ((TaskBuilder)(base.List[index]));}
set {base.List[index] = value;}
}
///
/// Gets the for the specified task.
///
/// The name of task for which the should be located in the collection.
[System.Runtime.CompilerServices.IndexerName("Item")]
public TaskBuilder this[string taskName] {
get {
if (taskName != null) {
// Try to locate instance using TaskName
foreach (TaskBuilder TaskBuilder in base.List) {
if (taskName.Equals(TaskBuilder.TaskName)) {
return TaskBuilder;
}
}
}
return null;
}
}
#endregion Public Instance Properties
#region Public Instance Methods
///
/// Adds a to the end of the collection.
///
/// The to be added to the end of the collection.
/// The position into which the new element was inserted.
public int Add(TaskBuilder item) {
return base.List.Add(item);
}
///
/// Adds the elements of a array to the end of the collection.
///
/// The array of elements to be added to the end of the collection.
public void AddRange(TaskBuilder[] items) {
for (int i = 0; (i < items.Length); i = (i + 1)) {
Add(items[i]);
}
}
///
/// Adds the elements of a to the end of the collection.
///
/// The to be added to the end of the collection.
public void AddRange(TaskBuilderCollection items) {
for (int i = 0; (i < items.Count); i = (i + 1)) {
Add(items[i]);
}
}
///
/// Determines whether a is in the collection.
///
/// The to locate in the collection.
///
/// if is found in the
/// collection; otherwise, .
///
public bool Contains(TaskBuilder item) {
return base.List.Contains(item);
}
///
/// Determines whether a for the specified
/// task is in the collection.
///
/// The name of task for which the should be located in the collection.
///
/// if a for the
/// specified task is found in the collection; otherwise, .
///
public bool Contains(string taskName) {
return this[taskName] != null;
}
///
/// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.
///
/// The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.
/// The zero-based index in at which copying begins.
public void CopyTo(TaskBuilder[] array, int index) {
base.List.CopyTo(array, index);
}
///
/// Retrieves the index of a specified object in the collection.
///
/// The object for which the index is returned.
///
/// The index of the specified . If the is not currently a member of the collection, it returns -1.
///
public int IndexOf(TaskBuilder item) {
return base.List.IndexOf(item);
}
///
/// Inserts a into the collection at the specified index.
///
/// The zero-based index at which should be inserted.
/// The to insert.
public void Insert(int index, TaskBuilder item) {
base.List.Insert(index, item);
}
///
/// Returns an enumerator that can iterate through the collection.
///
///
/// A for the entire collection.
///
public new TaskBuilderEnumerator GetEnumerator() {
return new TaskBuilderEnumerator(this);
}
///
/// Removes a member from the collection.
///
/// The to remove from the collection.
public void Remove(TaskBuilder item) {
base.List.Remove(item);
}
#endregion Public Instance Methods
}
///
/// Enumerates the elements of a .
///
public class TaskBuilderEnumerator : IEnumerator {
#region Internal Instance Constructors
///
/// Initializes a new instance of the class
/// with the specified .
///
/// The collection that should be enumerated.
internal TaskBuilderEnumerator(TaskBuilderCollection arguments) {
IEnumerable temp = (IEnumerable) (arguments);
_baseEnumerator = temp.GetEnumerator();
}
#endregion Internal Instance Constructors
#region Implementation of IEnumerator
///
/// Gets the current element in the collection.
///
///
/// The current element in the collection.
///
public TaskBuilder Current {
get { return (TaskBuilder) _baseEnumerator.Current; }
}
object IEnumerator.Current {
get { return _baseEnumerator.Current; }
}
///
/// Advances the enumerator to the next element of the collection.
///
///
/// if the enumerator was successfully advanced
/// to the next element; if the enumerator has
/// passed the end of the collection.
///
public bool MoveNext() {
return _baseEnumerator.MoveNext();
}
bool IEnumerator.MoveNext() {
return _baseEnumerator.MoveNext();
}
///
/// Sets the enumerator to its initial position, which is before the
/// first element in the collection.
///
public void Reset() {
_baseEnumerator.Reset();
}
void IEnumerator.Reset() {
_baseEnumerator.Reset();
}
#endregion Implementation of IEnumerator
#region Private Instance Fields
private IEnumerator _baseEnumerator;
#endregion Private Instance Fields
}
}