Skip to content

Commit

Permalink
- 增加 DynamicFilterCustom 参数 object sender;#1113
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed May 22, 2022
1 parent b49c487 commit 7903fc3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
9 changes: 9 additions & 0 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ public enum ts_dyfilter_enum01_status { staring, stoped, finished }
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)
{
Expand Down
7 changes: 5 additions & 2 deletions FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ public void WhereDynamicFilter()
""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'))""
},
Expand All @@ -2689,7 +2689,10 @@ public enum ts_dyfilter_enum01_status { staring, stoped, finished }
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)
{
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/FreeSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,13 @@ void ParseFilter(DynamicFilterLogic logic, DynamicFilterInfo fi, bool isend)
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;

Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Internal/Model/DynamicFilterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public enum DynamicFilterOperator
/// public class DynamicFilterCustom<para></para>
/// {<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>
/// </summary>
Expand Down

0 comments on commit 7903fc3

Please sign in to comment.