#define DEBUG using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; namespace AspClassic.Parser; /// /// A collection of a particular type of trees /// /// The type of tree the collection contains. public abstract class TreeCollection : Tree, IList where T : Tree { private ReadOnlyCollection _Trees; public int Count => _Trees.Count; private bool IsReadOnly => true; public T this[int index] => _Trees[index]; /*private T IListItem { get { return _Trees[index]; } set { throw new NotSupportedException(); } }*/ bool ICollection.IsReadOnly => IsReadOnly; T IList.this[int index] { get => _Trees[index]; set => throw new NotSupportedException(); } protected TreeCollection(TreeType type, IList trees, Span span) : base(type, span) { Debug.Assert(type >= TreeType.ArgumentCollection && type <= TreeType.DeclarationCollection); if (trees == null) { _Trees = new ReadOnlyCollection(new List()); return; } _Trees = new ReadOnlyCollection(trees); SetParents(trees); } private void Add(T item) { throw new NotSupportedException(); } void ICollection.Add(T item) { //ILSpy generated this explicit interface implementation from .override directive in Add this.Add(item); } private void Clear() { throw new NotSupportedException(); } void ICollection.Clear() { //ILSpy generated this explicit interface implementation from .override directive in Clear this.Clear(); } public bool Contains(T item) { return _Trees.Contains(item); } bool ICollection.Contains(T item) { //ILSpy generated this explicit interface implementation from .override directive in Contains return this.Contains(item); } public void CopyTo(T[] array, int arrayIndex) { _Trees.CopyTo(array, arrayIndex); } void ICollection.CopyTo(T[] array, int arrayIndex) { //ILSpy generated this explicit interface implementation from .override directive in CopyTo this.CopyTo(array, arrayIndex); } private bool Remove(T item) { throw new NotSupportedException(); } bool ICollection.Remove(T item) { //ILSpy generated this explicit interface implementation from .override directive in Remove return this.Remove(item); } public IEnumerator GetEnumerator() { return _Trees.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { //ILSpy generated this explicit interface implementation from .override directive in GetEnumerator return this.GetEnumerator(); } public int IndexOf(T item) { return _Trees.IndexOf(item); } int IList.IndexOf(T item) { //ILSpy generated this explicit interface implementation from .override directive in IndexOf return this.IndexOf(item); } private void Insert(int index, T item) { throw new NotSupportedException(); } void IList.Insert(int index, T item) { //ILSpy generated this explicit interface implementation from .override directive in Insert this.Insert(index, item); } private void RemoveAt(int index) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { //ILSpy generated this explicit interface implementation from .override directive in RemoveAt this.RemoveAt(index); } private IEnumerator IEnumerableGetEnumerator() { return _Trees.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { //ILSpy generated this explicit interface implementation from .override directive in IEnumerableGetEnumerator return this.IEnumerableGetEnumerator(); } protected override void GetChildTrees(IList childList) { Tree.AddChildren(childList, _Trees); } }