using System; using System.Collections.Generic; using System.Linq; using JLHHJSvr.Com.Model; namespace JLHHJSvr.LJFramework.Tools { public class menuRecursion { /// /// 递归查询 /// /// /// 要查找的全部内容 /// 要查找内容的主ID,名称,父ID /// 输出结构 public void GetRecursions(List TList, PkName pkName, List ReList, List idList) { //if (pkName.MainField == string.Empty || pkName.MainName == string.Empty || pkName.ParentField == string.Empty) //{ // return; //} var NTList = TList.Where(t => idList.IndexOf((int)t.GetType().GetProperty(pkName.MainField).GetValue(t)) == -1).ToList(); foreach (var mx in ReList) { var parentid = mx.value; var tmpList = NTList.Where(t => (int)t.GetType().GetProperty(pkName.ParentField).GetValue(t) == parentid).ToList(); if (tmpList.Count > 0) { mx.children = new List(); foreach (var tmp in tmpList) { var Child = new Recursion2() { text = Convert.ToString(tmp.GetType().GetProperty(pkName.MainName).GetValue(tmp)), value = Convert.ToInt32(tmp.GetType().GetProperty(pkName.MainField).GetValue(tmp)) }; mx.children.Add(Child); idList.Add(Child.value); } GetRecursions(TList, pkName, mx.children, idList); } } } } }