From 7903fc3effdea376e9745c58fba402c770e6b560 Mon Sep 17 00:00:00 2001
From: 2881099 <2881099@qq.com>
Date: Mon, 23 May 2022 01:22:45 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20DynamicFilterCustom=20?=
=?UTF-8?q?=E5=8F=82=E6=95=B0=20object=20sender=EF=BC=9B#1113?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FreeSql.DbContext/FreeSql.DbContext.xml | 9 +++++++++
.../Sqlite/Curd/SqliteSelectTest.cs | 2 +-
.../FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs | 7 +++++--
FreeSql/FreeSql.xml | 2 +-
.../CommonProvider/SelectProvider/Select0Provider.cs | 6 +++++-
FreeSql/Internal/Model/DynamicFilterInfo.cs | 2 +-
6 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml
index 4335acb5..d34b34ef 100644
--- a/FreeSql.DbContext/FreeSql.DbContext.xml
+++ b/FreeSql.DbContext/FreeSql.DbContext.xml
@@ -786,5 +786,14 @@
+
+
+ 批量注入 Repository,可以参考代码自行调整
+
+
+
+
+
+
diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Sqlite.Data/Sqlite/Curd/SqliteSelectTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Sqlite.Data/Sqlite/Curd/SqliteSelectTest.cs
index ad048023..b40fe1fb 100644
--- a/FreeSql.Tests/FreeSql.Tests.Provider.Sqlite.Data/Sqlite/Curd/SqliteSelectTest.cs
+++ b/FreeSql.Tests/FreeSql.Tests.Provider.Sqlite.Data/Sqlite/Curd/SqliteSelectTest.cs
@@ -2546,7 +2546,7 @@ WHERE (((name,no) in (('testname01','testname01')) OR not((a.""no"") LIKE '%test
public class DynamicFilterMyCustom
{
[DynamicFilterCustom]
- public static string MyRawSql(string value) => value;
+ public static string MyRawSql(object sender, string value) => value;
public static string TupleIn(string value)
{
diff --git a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
index 81f463e9..c438ae01 100644
--- a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
+++ b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
@@ -2664,7 +2664,7 @@ WHERE ((not((a.""name"") LIKE '%testname01') OR not((a.""no"") LIKE '%testname01
""Value"" : ""testname01""
},
{
- ""Field"" : ""MyRawSql FreeSql.Tests.Sqlite.DynamicFilterMyCustom,FreeSql.Tests"",
+ ""Field"" : ""MyRawSql2 FreeSql.Tests.Sqlite.DynamicFilterMyCustom,FreeSql.Tests"",
""Operator"" : ""Custom"",
""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
{
[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)
{
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index 3a83da5e..90d7f92e 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -4269,7 +4269,7 @@
public class DynamicFilterCustom
{
[DynamicFilterCustom]
- public static string RawSql(string value) => value;
+ public static string RawSql(object sender, string value) => value;
}
}
diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
index e47c22e3..2ed9ffa2 100644
--- a/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
+++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
@@ -656,9 +656,13 @@ namespace FreeSql.Internal.CommonProvider
var fiValue1Type = Type.GetType(fiValueCustomArray[1]);
if (fiValue1Type == null) throw new ArgumentException(CoreStrings.NotFound_Reflection(fiValueCustomArray[1]));
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 (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)));
break;
diff --git a/FreeSql/Internal/Model/DynamicFilterInfo.cs b/FreeSql/Internal/Model/DynamicFilterInfo.cs
index 7b025e76..201b9c6c 100644
--- a/FreeSql/Internal/Model/DynamicFilterInfo.cs
+++ b/FreeSql/Internal/Model/DynamicFilterInfo.cs
@@ -132,7 +132,7 @@ namespace FreeSql.Internal.Model
/// public class DynamicFilterCustom
/// {
/// [DynamicFilterCustom]
- /// public static string RawSql(string value) => value;
+ /// public static string RawSql(object sender, string value) => value;
/// }
/// }
///