编程语言
首页 > 编程语言> > C# 递归将n级实体类转换为一维数据源

C# 递归将n级实体类转换为一维数据源

作者:互联网

/// <summary>
        /// 将父子级数据结构转换为普通list
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List<UniWater_MenuInfo> GetMenuInfoList(List<UniWater_MenuInfo> list)
        {
            List<UniWater_MenuInfo> Resultlist = new List<UniWater_MenuInfo>();
            foreach (var item in list)
            {
                OperationChildData(Resultlist, item);
                Resultlist.Add(item);
            }
            return Resultlist;
        }
        /// <summary>
        /// 递归子级数据
        /// </summary>
        /// <param name="treeDataList">树形列表数据</param>
        /// <param name="parentItem">父级model</param>
        public static void OperationChildData(List<UniWater_MenuInfo> AllList, UniWater_MenuInfo item)
        {
            if (item.children != null)
            {
                if (item.children.Count > 0)
                {
                    AllList.AddRange(item.children);
                    foreach (var subItem in item.children)
                    {
                        OperationChildData(AllList, subItem);
                    }
                }
            }
        }

转自:http://www.manongjc.com/detail/17-cwfkfdaeqrbjqyr.html

标签:实体类,OperationChildData,C#,数据源,List,Resultlist,item,list,children
来源: https://blog.csdn.net/MonkeyBananas/article/details/116986163