mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add SqlFunc.OnlyInSelectConvertToString(it.name,methodInfo)
This commit is contained in:
parent
1539dffd28
commit
0a95b319f2
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -13,5 +14,6 @@ namespace SqlSugar
|
|||||||
public string Format { get; set; }
|
public string Format { get; set; }
|
||||||
public string PropertyName { get; set; }
|
public string PropertyName { get; set; }
|
||||||
public string MethodName { get; set; }
|
public string MethodName { get; set; }
|
||||||
|
public MethodInfo MethodInfo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -392,5 +393,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
throw new NotSupportedException("Can only be used in expressions");
|
throw new NotSupportedException("Can only be used in expressions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string OnlyInSelectConvertToString(string stringValue, MethodInfo methodInfo)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Can only be used in expressions");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,5 +263,20 @@ namespace SqlSugar
|
|||||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, "-");
|
this.Context.Result.Replace(ExpressionConst.FormatSymbol, "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void AppendOnlyInSelectConvertToString(ExpressionParameter parameter, Expression item, string asName)
|
||||||
|
{
|
||||||
|
var name =GetNewExpressionValue((item as MethodCallExpression)?.Arguments[0]);
|
||||||
|
var methodInfo = ExpressionTool.DynamicInvoke(((item as MethodCallExpression)?.Arguments[1]));
|
||||||
|
if (this.Context.SugarContext.QueryBuilder.QueryableFormats == null)
|
||||||
|
this.Context.SugarContext.QueryBuilder.QueryableFormats = new List<QueryableFormat>();
|
||||||
|
this.Context.SugarContext.QueryBuilder.QueryableFormats.Add(new QueryableFormat()
|
||||||
|
{
|
||||||
|
Format = "",
|
||||||
|
PropertyName = asName,
|
||||||
|
MethodName = "OnlyInSelectConvertToString",
|
||||||
|
MethodInfo= (MethodInfo)methodInfo
|
||||||
|
});
|
||||||
|
parameter.Context.Result.Append(this.Context.GetAsString2(asName, name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,11 @@ namespace SqlSugar
|
|||||||
parameter.Context.Result.Append(this.Context.GetAsString2(asName, this.Context.DbMehtods.NewUid(null)));
|
parameter.Context.Result.Append(this.Context.GetAsString2(asName, this.Context.DbMehtods.NewUid(null)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (ExpressionTool.GetMethodName(item) == "OnlyInSelectConvertToString")
|
||||||
|
{
|
||||||
|
AppendOnlyInSelectConvertToString(parameter, item, asName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else if (ExpressionTool.GetMethodName(item) == "ToString"
|
else if (ExpressionTool.GetMethodName(item) == "ToString"
|
||||||
&&(item as MethodCallExpression)?.Arguments?.Count()==1
|
&&(item as MethodCallExpression)?.Arguments?.Count()==1
|
||||||
&& (item as MethodCallExpression)?.Object?.Type!=UtilConstants.DateType
|
&& (item as MethodCallExpression)?.Object?.Type!=UtilConstants.DateType
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>SqlSugarCore</id>
|
<id>SqlSugarCore</id>
|
||||||
<version>5.1.4.111</version>
|
<version>5.1.4.113-preview28</version>
|
||||||
<authors>sunkaixuan</authors>
|
<authors>sunkaixuan</authors>
|
||||||
<owners>果糖大数据科技</owners>
|
<owners>果糖大数据科技</owners>
|
||||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||||
|
@ -135,9 +135,25 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
addValue = Convert.ToDouble(addValue + "").ToString(valueFomatInfo.Format);
|
addValue = Convert.ToDouble(addValue + "").ToString(valueFomatInfo.Format);
|
||||||
}
|
}
|
||||||
else if (valueFomatInfo.TypeString == "Enum")
|
else if (valueFomatInfo.TypeString == "Enum")
|
||||||
{
|
{
|
||||||
addValue =ChangeType2( addValue,valueFomatInfo.Type)?.ToString();
|
addValue =ChangeType2(addValue, valueFomatInfo.Type)?.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (valueFomatInfo.MethodName== "OnlyInSelectConvertToString")
|
||||||
|
{
|
||||||
|
|
||||||
|
var methodInfo = valueFomatInfo.MethodInfo;
|
||||||
|
if (methodInfo != null)
|
||||||
|
{
|
||||||
|
// 如果方法是静态的,传递null作为第一个参数,否则传递类的实例
|
||||||
|
object instance = methodInfo.IsStatic ? null : Activator.CreateInstance(methodInfo.ReflectedType);
|
||||||
|
|
||||||
|
// 创建一个包含参数值的object数组
|
||||||
|
object[] parameters = new object[] { addValue };
|
||||||
|
|
||||||
|
// 调用方法
|
||||||
|
addValue=methodInfo.Invoke(instance, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return addValue;
|
return addValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user