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