Beispiel #1
0
        public static ODTO_Tree <TEntity> ToTree <TEntity, TKey>(this List <TEntity> sourceDataList, TKey pathTag = default) where TEntity : class, IDBField_Tree <TKey>
        {
            ODTO_Tree <TEntity> tree = new ODTO_Tree <TEntity>();

            var query = sourceDataList.AsQueryable();

            if (pathTag == null)
            {
                query = query.Where(o => o.ParentNode == null);
            }
            else
            {
                query = query.Where(o => o.ParentNode != null && o.ParentNode.ToString() == pathTag.ToString());
            }

            List <TEntity> dataList = query.ToList();

            foreach (TEntity data in dataList)
            {
                ODTO_TreeNode <TEntity> treeNode = new ODTO_TreeNode <TEntity>();
                treeNode.Info   = data;
                treeNode.Childs = sourceDataList.ToTree(data.CurNode);

                tree.Add(treeNode);
            }

            return(tree);
        }
Beispiel #2
0
 public ODTO_TreeNode()
 {
     Info   = default(T);
     Childs = new ODTO_Tree <T>();
 }