From e61c9712d487dde94e1ab80c533e16799b33e554 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 11 Jul 2023 13:02:32 +0800 Subject: [PATCH] Synchronization code --- .../DbMethods/DefaultDbMethod.cs | 39 ++++++++++++++++++- .../MethodCallExpressionResolve_Helper.cs | 8 ++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index 3d8147f16..92344e3cb 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -562,7 +562,18 @@ namespace SqlSugar { var str = model.Args[0].MemberValue.ObjToString(); var array = model.Args.Skip(1).Select(it => it.IsMember ? it.MemberName : it.MemberValue).ToArray(); - return string.Format("'" + str + "'", array); + if (array.Length == 1 && array[0] is string[]) + { + List args = GetStringFormatArgs(str, array[0] as string[]); + return Format(new MethodCallExpressionModel() + { + Args = args + }); ; + } + else + { + return string.Format("'" + str + "'", array); + } } public virtual string Format(MethodCallExpressionModel model) { @@ -573,6 +584,14 @@ namespace SqlSugar { return FormatConcat(model); } + if (model.Args.Count == 2 && model.Args[1].MemberValue is string[]) + { + List args = GetStringFormatArgs(str, model.Args[1].MemberValue as string[]); + return Format(new MethodCallExpressionModel() + { + Args = args + }); ; + } str =Regex.Replace(str, @"(\{\d+?\})", revalue); var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:(it.MemberValue==null?"''":it.MemberValue.ToSqlValue())) .Select(it=>ToString(new MethodCallExpressionModel() { Args=new List() { @@ -969,6 +988,24 @@ namespace SqlSugar } } + private static List GetStringFormatArgs(string str, object array) + { + var args = new List() + { + new MethodCallExpressionArgs(){ + MemberName=str, + MemberValue=str + } + }; + args.AddRange((array as string[]).Select(it => new MethodCallExpressionArgs() + { + MemberValue = it, + MemberName = it + + })); + return args; + } + public virtual string WeekOfYear(MethodCallExpressionModel mode) { var parameterNameA = mode.Args[0].MemberName; diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs index 24f486986..2e35e1d65 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs @@ -366,6 +366,14 @@ namespace SqlSugar { parameter.CommonTempData = GetNewExpressionValue(item); } + else if (name == "Format" && item is NewArrayExpression) + { + var exps = (item as NewArrayExpression).Expressions; + parameter.CommonTempData = exps.Select(it => { + var res = GetNewExpressionValue(ExpressionTool.RemoveConvert(it)); + return res; + }).ToArray(); + } else { base.Start();