168 lines
3.7 KiB
C#
168 lines
3.7 KiB
C#
#define DEBUG
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
|
|
namespace AspClassic.Parser;
|
|
|
|
/// <summary>
|
|
/// A collection of a particular type of trees
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of tree the collection contains.</typeparam>
|
|
public abstract class TreeCollection<T> : Tree, IList<T> where T : Tree
|
|
{
|
|
private ReadOnlyCollection<T> _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<T>.IsReadOnly => IsReadOnly;
|
|
|
|
|
|
T IList<T>.this[int index] { get => _Trees[index]; set => throw new NotSupportedException(); }
|
|
|
|
protected TreeCollection(TreeType type, IList<T> trees, Span span)
|
|
: base(type, span)
|
|
{
|
|
Debug.Assert(type >= TreeType.ArgumentCollection && type <= TreeType.DeclarationCollection);
|
|
if (trees == null)
|
|
{
|
|
_Trees = new ReadOnlyCollection<T>(new List<T>());
|
|
return;
|
|
}
|
|
_Trees = new ReadOnlyCollection<T>(trees);
|
|
SetParents(trees);
|
|
}
|
|
|
|
private void Add(T item)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
void ICollection<T>.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<T>.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<T>.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<T>.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<T>.Remove(T item)
|
|
{
|
|
//ILSpy generated this explicit interface implementation from .override directive in Remove
|
|
return this.Remove(item);
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return _Trees.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator<T> IEnumerable<T>.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<T>.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<T>.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<T>.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<Tree> childList)
|
|
{
|
|
Tree.AddChildren(childList, _Trees);
|
|
}
|
|
}
|