diff --git a/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs b/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs index 34fb2bedf..1ef870339 100644 --- a/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs +++ b/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs @@ -29,5 +29,6 @@ namespace SqlSugar public static bool EnableAllWhereIF = false; public static Func Check_FieldFunc; public static Type DynamicExpressionParserType; + public static object DynamicExpressionParsingConfig; } } diff --git a/Src/Asp.NetCore2/SqlSugar/Json2Sql/DynamicLinq/SqlSugarDynamicExpressionParser.cs b/Src/Asp.NetCore2/SqlSugar/Json2Sql/DynamicLinq/SqlSugarDynamicExpressionParser.cs index 88393cdee..4d306dff8 100644 --- a/Src/Asp.NetCore2/SqlSugar/Json2Sql/DynamicLinq/SqlSugarDynamicExpressionParser.cs +++ b/Src/Asp.NetCore2/SqlSugar/Json2Sql/DynamicLinq/SqlSugarDynamicExpressionParser.cs @@ -16,19 +16,39 @@ namespace SqlSugar 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) + if (StaticConfig.DynamicExpressionParsingConfig != null) { - throw new InvalidOperationException("ParseLambda method not found in DynamicExpressionParserType."); + // 查找 ParseLambda 方法 + MethodInfo parseLambdaMethod = StaticConfig.DynamicExpressionParserType + .GetMyMethod("ParseLambda", 5, StaticConfig.DynamicExpressionParsingConfig.GetType(), 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[] { StaticConfig.DynamicExpressionParsingConfig, parameterExpressions, type, sql, objects }); + + return lambda; } + else + { - // 调用 ParseLambda 方法来解析 Lambda 表达式 - var lambda = (LambdaExpression)parseLambdaMethod.Invoke(null, new object[] { parameterExpressions, type, sql, objects }); + // 查找 ParseLambda 方法 + MethodInfo parseLambdaMethod = StaticConfig.DynamicExpressionParserType + .GetMyMethod("ParseLambda",4, typeof(ParameterExpression[]), typeof(Type), typeof(string), typeof(object[])); - return lambda; + 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; + } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs index 3a855fb28..ceb0602b9 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs @@ -72,6 +72,16 @@ namespace SqlSugar it.GetParameters()[2].ParameterType == parameterType3&& it.GetParameters()[3].ParameterType == parameterType4); } + public static MethodInfo GetMyMethod(this Type type, string name, int argCount, Type parameterType, Type parameterType2, Type parameterType3, Type parameterType4, Type parameterType5) + { + return type.GetMethods().Where(it => it.Name == name).FirstOrDefault(it => + it.GetParameters().Length == argCount && + it.GetParameters().First().ParameterType == parameterType && + it.GetParameters()[1].ParameterType == parameterType2 && + it.GetParameters()[2].ParameterType == parameterType3 && + it.GetParameters()[3].ParameterType == parameterType4&& + it.GetParameters()[4].ParameterType == parameterType5); + } public static List ToList(this T thisValue,Func action) where T:class,new() { return new List { thisValue };