/// <summary> /// 无论如何都添加 /// </summary> /// <param name="child"></param> public void ChildAdd(T child) { TreeBase <T> t = new TreeBase <T>(child); t.parent = this; parent.childs.Add(t); }
/// <summary> /// 子元素索引 /// </summary> /// <param name="child"></param> /// <returns></returns> public int ChildIndexOf(T child) { TreeBase <T> old = childs.FirstOrDefault <TreeBase <T> >(x => x.Data.Equals(child)); if (old == null) { return(-1); } return(childs.IndexOf(old)); }
/// <summary> /// 如果child已经不存在,则添加 /// </summary> /// <param name="child"></param> public void ChildPut(T child) { TreeBase <T> old = childs.FirstOrDefault <TreeBase <T> >(x => x.Data.Equals(child)); if (old == null) { old = new TreeBase <T>(child); old.parent = this; parent.childs.Add(old); return; } old.parent = this; }