using System.Collections; namespace XFEExtension.NetCore.XFETransform.ObjectInfoAnalyzer; internal abstract class SubObjectsBase : ISubObjects { protected readonly List ObjectInfoList; protected SubObjectsBase(List? objectInfoList, IObjectInfo parent) { this.ObjectInfoList = objectInfoList ?? []; Parent = parent; objectInfoList?.ForEach(objectInfo => objectInfo.Parent = parent); } /// /// 获取或设置指定索引处的子对象信息。 /// /// 要访问的子对象索引。 /// 指定索引处的子对象信息。 public IObjectInfo this[int index] { get => ObjectInfoList[index]; set => ObjectInfoList[index] = value; } /// /// 获取当前集合包含的子对象数量。 /// public int Count => ObjectInfoList.Count; /// /// 获取一个值,指示当前子对象集合是否为只读;该实现始终返回 。 /// public bool IsReadOnly => false; /// /// 获取拥有当前子对象集合的父对象信息。 /// public IObjectInfo Parent { get; init; } /// /// 将对象信息添加到子对象集合末尾。 /// /// 要添加的对象信息。 public void Add(IObjectInfo item) => ObjectInfoList.Add(item); /// /// 从当前集合中移除全部子对象信息。 /// public void Clear() => ObjectInfoList.Clear(); /// /// 确定当前集合是否包含指定的对象信息。 /// /// 要在集合中查找的对象信息。 /// 集合包含指定对象信息时为 ;否则为 public bool Contains(IObjectInfo item) => ObjectInfoList.Contains(item); /// /// 从指定数组索引开始,将当前集合中的全部子对象复制到目标数组。 /// /// 接收子对象信息的目标数组。 /// 目标数组中开始写入的从零开始的索引。 public void CopyTo(IObjectInfo[] array, int arrayIndex) => ObjectInfoList.CopyTo(array, arrayIndex); /// /// 获取用于遍历当前子对象集合的泛型枚举器。 /// /// 当前子对象集合的泛型枚举器。 public IEnumerator GetEnumerator() => ObjectInfoList.GetEnumerator(); /// /// 查找指定对象信息并返回其从零开始的索引。 /// /// 要在集合中查找的对象信息。 /// 找到指定对象信息时返回其索引;否则返回 -1。 public int IndexOf(IObjectInfo item) => ObjectInfoList.IndexOf(item); /// /// 将对象信息插入当前集合的指定索引处。 /// /// 插入对象信息的从零开始的索引。 /// 要插入的对象信息。 public void Insert(int index, IObjectInfo item) => ObjectInfoList.Insert(index, item); /// /// 从当前集合中移除首次出现的指定对象信息。 /// /// 要移除的对象信息。 /// 成功移除对象信息时为 ;否则为 public bool Remove(IObjectInfo item) => ObjectInfoList.Remove(item); /// /// 移除当前集合中指定索引处的子对象信息。 /// /// 要移除的子对象索引。 public void RemoveAt(int index) => ObjectInfoList.RemoveAt(index); IEnumerator IEnumerable.GetEnumerator() => ObjectInfoList.GetEnumerator(); }