public List<dynamic> GetData(IDbConnection connection)
{
Func<int, List<dynamic>, List<dynamic>> DiguiChild = null;
DiguiChild = new Func<int, List<dynamic>, List<dynamic>>((pid, plist) =>
{
List<dynamic> childlist = new List<dynamic>();
foreach (var menu in plist)
{
if (menu.ParentId != null && menu.ParentId > 0)
{
if (menu.ParentId == pid)
{
childlist.Add(menu);
}
}
}
foreach (var menu in childlist)
{
menu.Child = DiguiChild (menu.Id, plist);
}
return childlist;
});
Func<List<dynamic>,List<dynamic>> Genter = new Func<List<dynamic>,List<dynamic>>((levellist) =>
{
var result = levellist.Where(x => x.ParentId==null).ToList();
foreach (var c in result)
{
c.Child = DiguiChild (c.Id, levellist);
}
return result;
});
}
来源:https://www.iwmyx.cn/fftzdydgff.html 标签:Func,递归,menu,List,childlist,体中,ParentId,var,方法 From: https://www.cnblogs.com/star8521/p/16739156.html