mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-24 04:53:45 +08:00
Add: DynamicLinq
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SqlSugarDynamicExpressionParser
|
||||
{
|
||||
|
||||
public static LambdaExpression ParseLambda(ParameterExpression[] parameterExpressions, Type type, string sql, object[] objects)
|
||||
{
|
||||
if (StaticConfig.DynamicExpressionParserType == null)
|
||||
{
|
||||
Check.ExceptionEasy("Please at program startup assignment: StaticConfig DynamicExpressionParserType = typeof (DynamicExpressionParser); NUGET is required to install Dynamic.Core", "请在程序启动时赋值: StaticConfig.DynamicExpressionParserType = typeof(DynamicExpressionParser); 需要NUGET安装 Dynamic.Core");
|
||||
}
|
||||
|
||||
// 查找 ParseLambda 方法
|
||||
MethodInfo parseLambdaMethod = StaticConfig.DynamicExpressionParserType
|
||||
.GetMyMethod("ParseLambda",4, typeof(ParameterExpression[]), typeof(Type), typeof(string), typeof(object[]));
|
||||
|
||||
if (parseLambdaMethod == null)
|
||||
{
|
||||
throw new InvalidOperationException("ParseLambda method not found in DynamicExpressionParserType.");
|
||||
}
|
||||
|
||||
// 调用 ParseLambda 方法来解析 Lambda 表达式
|
||||
var lambda = (LambdaExpression)parseLambdaMethod.Invoke(null, new object[] { parameterExpressions, type, sql, objects });
|
||||
|
||||
return lambda;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user