Update Json 2 sql

This commit is contained in:
sunkaixuan
2023-09-20 20:07:36 +08:00
parent e8924566e6
commit 4ed4445712
3 changed files with 40 additions and 9 deletions

View File

@@ -29,5 +29,6 @@ namespace SqlSugar
public static bool EnableAllWhereIF = false;
public static Func<string,string> Check_FieldFunc;
public static Type DynamicExpressionParserType;
public static object DynamicExpressionParsingConfig;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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<T> ToList<T>(this T thisValue,Func<T,T> action) where T:class,new()
{
return new List<T> { thisValue };