添加项目文件。

This commit is contained in:
zel
2025-03-05 19:42:01 +08:00
parent 659f1a2ad9
commit 47dcdeb55d
582 changed files with 242004 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright © 2016 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace WaterCloud.Code
{
public static class TreeQuery
{
public static List<T> TreeWhere<T>(this List<T> entityList, Predicate<T> condition, string keyValue = "F_Id", string parentId = "F_ParentId") where T : class
{
List<T> locateList = entityList.FindAll(condition);
var parameter = Expression.Parameter(typeof(T), "t");
List<T> treeList = new List<T>();
foreach (T entity in locateList)
{
treeList.Add(entity);
string pId = entity.GetType().GetProperty(parentId).GetValue(entity, null).ToString();
while (true)
{
if (string.IsNullOrEmpty(pId) && pId == "0")
{
break;
}
Predicate<T> upLambda = (Expression.Equal(parameter.Property(keyValue), Expression.Constant(pId))).ToLambda<Predicate<T>>(parameter).Compile();
T upRecord = entityList.Find(upLambda);
if (upRecord != null)
{
treeList.Add(upRecord);
pId = upRecord.GetType().GetProperty(parentId).GetValue(upRecord, null).ToString();
}
else
{
break;
}
}
}
return treeList.Distinct().ToList();
}
}
}