using System; using System.Collections.Generic; using System.Text; namespace Svg { /// /// Represents a collection of s. /// public sealed class SvgElementCollection : IList { private List _elements; private SvgElement _owner; /// /// Initialises a new instance of an class. /// /// The owner of the collection. internal SvgElementCollection(SvgElement owner) { if (owner == null) { throw new ArgumentNullException("owner"); } this._elements = new List(); this._owner = owner; } /// /// Returns the index of the specified in the collection. /// /// The to search for. /// The index of the element if it is present; otherwise -1. public int IndexOf(SvgElement item) { return this._elements.IndexOf(item); } /// /// Inserts the given to the collection at the specified index. /// /// The index that the should be added at. /// The to be added. public void Insert(int index, SvgElement item) { this._elements.Insert(index, item); } public void RemoveAt(int index) { SvgElement element = this[index]; if (element != null) this.Remove(element); } public SvgElement this[int index] { get { return this._elements[index]; } set { this._elements[index] = value; } } public void Add(SvgElement item) { if (this._owner.OwnerDocument != null) { this._owner.OwnerDocument.IdManager.Add(item); } this._elements.Add(item); item._parent = this._owner; item._parent.OnElementAdded(item, this.Count - 1); } public void Clear() { while (this.Count > 0) { SvgElement element = this[0]; this.Remove(element); } } public bool Contains(SvgElement item) { return this._elements.Contains(item); } public void CopyTo(SvgElement[] array, int arrayIndex) { this._elements.CopyTo(array, arrayIndex); } public int Count { get { return this._elements.Count; } } public bool IsReadOnly { get { return false; } } public bool Remove(SvgElement item) { bool removed = this._elements.Remove(item); if (removed) { this._owner.OnElementRemoved(item); item._parent = null; if (this._owner.OwnerDocument != null) { this._owner.OwnerDocument.IdManager.Remove(item); } } return removed; } public IEnumerator GetEnumerator() { return this._elements.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this._elements.GetEnumerator(); } } }