protected BaseLeaf <TKey> FindNodeByName(string name, BaseLeaf <TKey> currNode) { if (currNode.IsNull()) { return(default(TNode)); } if (currNode.Name.Equals(name)) { return(currNode); } if (currNode is TNode) { var n = (TNode)currNode; if (n.ChildrenNodes.HasItem()) { foreach (var item in n.ChildrenNodes) { if (item.Name.Equals(name)) { return(item as BaseLeaf <TKey>); } } } } else { if (currNode.Name.Equals(name)) { return(currNode); } } return(default(TNode)); }
/// <summary> /// 定位路径字符串,/name/name 这种风格 /// 算法还需优化 /// </summary> /// <param name="pathStr"></param> /// <returns></returns> public BaseLeaf <TKey> LocationPath(string pathStr) { var pathArray = pathStr.Split('/'); BaseLeaf <TKey> thisNode = this.TreeRoot; if (pathArray.Any()) { for (var i = 0; i < pathArray.Length; i++) { if (i == 0 && pathArray[i].NullEmpty()) { continue; } if (pathArray[i].NotNullEmpty() && thisNode.NotNull()) { var nname = pathArray[i]; thisNode = FindNodeByName(nname, thisNode); if (thisNode.IsNull()) { break; } } } } return(thisNode); }