- 增加 DynamicFilterCustom 参数 object sender;#1113

This commit is contained in:
2881099 2022-05-23 01:22:45 +08:00
parent b49c487906
commit 7903fc3eff
6 changed files with 22 additions and 6 deletions

View File

@ -786,5 +786,14 @@
<param name="that"></param> <param name="that"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
<summary>
批量注入 Repository可以参考代码自行调整
</summary>
<param name="services"></param>
<param name="globalDataFilter"></param>
<param name="assemblies"></param>
<returns></returns>
</member>
</members> </members>
</doc> </doc>

View File

@ -2546,7 +2546,7 @@ WHERE (((name,no) in (('testname01','testname01')) OR not((a.""no"") LIKE '%test
public class DynamicFilterMyCustom public class DynamicFilterMyCustom
{ {
[DynamicFilterCustom] [DynamicFilterCustom]
public static string MyRawSql(string value) => value; public static string MyRawSql(object sender, string value) => value;
public static string TupleIn(string value) public static string TupleIn(string value)
{ {

View File

@ -2664,7 +2664,7 @@ WHERE ((not((a.""name"") LIKE '%testname01') OR not((a.""no"") LIKE '%testname01
""Value"" : ""testname01"" ""Value"" : ""testname01""
}, },
{ {
""Field"" : ""MyRawSql FreeSql.Tests.Sqlite.DynamicFilterMyCustom,FreeSql.Tests"", ""Field"" : ""MyRawSql2 FreeSql.Tests.Sqlite.DynamicFilterMyCustom,FreeSql.Tests"",
""Operator"" : ""Custom"", ""Operator"" : ""Custom"",
""Value"" : ""(id,status) in (('testname01','finished'))"" ""Value"" : ""(id,status) in (('testname01','finished'))""
}, },
@ -2689,7 +2689,10 @@ WHERE (((name,no) in (('testname01','testname01')) OR not((a.""no"") LIKE '%test
public class DynamicFilterMyCustom public class DynamicFilterMyCustom
{ {
[DynamicFilterCustom] [DynamicFilterCustom]
public static string MyRawSql(string value) => value; public static string MyRawSql(object sender, string value) => value;
[DynamicFilterCustom]
public static string MyRawSql2(string value) => value;
public static string TupleIn(string value) public static string TupleIn(string value)
{ {

View File

@ -4269,7 +4269,7 @@
public class DynamicFilterCustom<para></para> public class DynamicFilterCustom<para></para>
{<para></para> {<para></para>
[DynamicFilterCustom]<para></para> [DynamicFilterCustom]<para></para>
public static string RawSql(string value) => value;<para></para> public static string RawSql(object sender, string value) => value;<para></para>
}<para></para> }<para></para>
}<para></para> }<para></para>
</summary> </summary>

View File

@ -656,9 +656,13 @@ namespace FreeSql.Internal.CommonProvider
var fiValue1Type = Type.GetType(fiValueCustomArray[1]); var fiValue1Type = Type.GetType(fiValueCustomArray[1]);
if (fiValue1Type == null) throw new ArgumentException(CoreStrings.NotFound_Reflection(fiValueCustomArray[1])); if (fiValue1Type == null) throw new ArgumentException(CoreStrings.NotFound_Reflection(fiValueCustomArray[1]));
var fiValue0Method = fiValue1Type.GetMethod(fiValueCustomArray[0], new Type[] { typeof(string) }); var fiValue0Method = fiValue1Type.GetMethod(fiValueCustomArray[0], new Type[] { typeof(string) });
if (fiValue0Method == null) fiValue0Method = fiValue1Type.GetMethod(fiValueCustomArray[0], new Type[] { typeof(object), typeof(string) });
if (fiValue0Method == null) throw new ArgumentException(CoreStrings.NotFound_Static_MethodName(fiValueCustomArray[0])); if (fiValue0Method == null) throw new ArgumentException(CoreStrings.NotFound_Static_MethodName(fiValueCustomArray[0]));
if (MethodIsDynamicFilterCustomAttribute(fiValue0Method) == false) throw new ArgumentException(CoreStrings.Custom_StaticMethodName_NotSet_DynamicFilterCustom(fiValueCustomArray[0])); if (MethodIsDynamicFilterCustomAttribute(fiValue0Method) == false) throw new ArgumentException(CoreStrings.Custom_StaticMethodName_NotSet_DynamicFilterCustom(fiValueCustomArray[0]));
var fiValue0MethodReturn = fiValue0Method?.Invoke(null, new object[] { fi.Value?.ToString() })?.ToString(); var fiValue0MethodReturn = fiValue0Method?.Invoke(null, fiValue0Method.GetParameters()
.Select(a => a.ParameterType == typeof(object) ? (object)this :
(a.ParameterType == typeof(string) ? (object)(fi.Value?.ToString()) : (object)null))
.ToArray())?.ToString();
exp = Expression.Call(typeof(SqlExt).GetMethod("InternalRawSql", BindingFlags.NonPublic | BindingFlags.Static), Expression.Constant(fiValue0MethodReturn, typeof(string))); exp = Expression.Call(typeof(SqlExt).GetMethod("InternalRawSql", BindingFlags.NonPublic | BindingFlags.Static), Expression.Constant(fiValue0MethodReturn, typeof(string)));
break; break;

View File

@ -132,7 +132,7 @@ namespace FreeSql.Internal.Model
/// public class DynamicFilterCustom<para></para> /// public class DynamicFilterCustom<para></para>
/// {<para></para> /// {<para></para>
/// [DynamicFilterCustom]<para></para> /// [DynamicFilterCustom]<para></para>
/// public static string RawSql(string value) => value;<para></para> /// public static string RawSql(object sender, string value) => value;<para></para>
/// }<para></para> /// }<para></para>
/// }<para></para> /// }<para></para>
/// </summary> /// </summary>