Example #1
0
        /// <summary>
        /// 将Tree结构转为平铺
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List <T> TreeToList <T>(List <T> tree, string field)
        {
            if (tree == null)
            {
                return(null);
            }
            List <T> list = new List <T>();

            foreach (T item in tree)
            {
                list.Add(item);

                List <T> child = Reflex.GetValByField <List <T> >(item, field);

                List <T> temp = TreeToList(child, field);
                if (temp != null && temp.Count > 0)
                {
                    list.AddRange(temp);
                }
            }
            return(list);
        }