Exemple #1
0
 /// <summary>
 /// 设置节点集合并返回子树内容
 /// </summary>
 /// <typeparam name="T">实体类型</typeparam>
 /// <param name="items">节点集合</param>
 /// <returns></returns>
 public BuildChildrenContext <T> SetItems <T>(IEnumerable <T> items)
 {
     foreach (var item in items)
     {
         var node = TreeBuilder.BuildNode(item);
         Tree.Add(node);
     }
     return(new BuildChildrenContext <T>(Tree));
 }
        /// <summary>
        /// 设置节点集合并返回子树节点上下文
        /// </summary>
        /// <typeparam name="V">实体类型</typeparam>
        /// <param name="itemSelector">节点集合选择器</param>
        /// <param name="textSelect">文本选择器</param>
        /// <returns></returns>
        public BuildChildrenContext <V> SetItems <V>(Func <T, IEnumerable <V> > itemSelector,
                                                     Func <V, string> textSelect = null)
        {
            var leafNodes = Tree.GetLeafNodes().OfType <TreeNode <T> >();

            foreach (TreeNode <T> leafNode in leafNodes)
            {
                foreach (var child in itemSelector(leafNode.Value))
                {
                    var node = TreeBuilder.BuildNode(child, textSelect);
                    leafNode.Add(node);
                }
            }
            return(new BuildChildrenContext <V>(Tree));
        }