Ejemplo n.º 1
0
        /// <summary>
        /// 找到指定名称的子节点,递归或不递归方式。
        /// </summary>
        /// <param name="name">子节点名称</param>
        /// <param name="recursive">是否递归查找子节点的子节点?</param>
        /// <returns>指定名称的子节点</returns>
        public ViNamedObject ChildByName(string name, bool recursive)
        {
            int index = this.IndexOfChild(name);

            if (index < 0)
            {
                if (recursive)
                {
                    foreach (ViNamedObject child in this.Children)
                    {
                        SortedTreeObject treeobj = child as SortedTreeObject;
                        if (treeobj == null)
                        {
                            continue;
                        }

                        ViNamedObject findobj = treeobj.ChildByName(name, recursive);
                        if (findobj != null)
                        {
                            return(findobj);
                        }
                    }
                }
                return(null);
            }

            return(this.Children[index]);
        }
Ejemplo n.º 2
0
        protected ViNamedObject ChildByPath(string[] path, int start)
        {
            ViNamedObject child = this.ChildByName(path[start], false);

            if (child == null)
            {
                return(null);
            }

            if (start + 1 >= path.Count())
            {
                return(child);
            }

            SortedTreeObject treeobj = child as SortedTreeObject;

            if (treeobj == null)
            {
                return(null);
            }

            return(treeobj.ChildByPath(path, start + 1));
        }