Skip to content

Commit a7e987d

Browse files
committed
[#148] 支持like操作符的提取
1 parent 3f44744 commit a7e987d

File tree

8 files changed

+985
-841
lines changed

8 files changed

+985
-841
lines changed

src/ShardingCore/Core/VirtualRoutes/ShardingOperatorEnum.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public enum ShardingOperatorEnum
2424
Equal,
2525
[Description("!=")]
2626
NotEqual,
27-
// [Description("%w%")]
28-
// AllLike,
29-
// [Description("%w")]
30-
// StartLike,
31-
// [Description("w%")]
32-
// EndLike
27+
[Description("%w%")]
28+
AllLike,
29+
[Description("%w")]
30+
StartLike,
31+
[Description("w%")]
32+
EndLike
3333
// [Description("Contains")]
3434
// BeContains
3535
}

src/ShardingCore/Extensions/CommonExtension.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,26 @@ public static bool IsShardingTableDbContext(this Type dbContextType)
8080
/// 是否是集合contains方法
8181
/// </summary>
8282
/// <param name="express"></param>
83-
/// <param name="methodName"></param>
8483
/// <returns></returns>
85-
public static bool IsEnumerableContains(this MethodCallExpression express, string methodName)
84+
public static bool IsEnumerableContains(this MethodCallExpression express)
8685
{
87-
return express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == nameof(IList.Contains);
86+
var methodName = express.Method.Name;
87+
return methodName == nameof(IList.Contains)&& (express.Method.DeclaringType?.Namespace.IsInEnumerable()??false);
88+
}
89+
public static bool IsStringContains(this MethodCallExpression express)
90+
{
91+
var methodName = express.Method.Name;
92+
return methodName == nameof(string.Contains)&& (express.Method.DeclaringType==typeof(string));
93+
}
94+
public static bool IsStringStartWith(this MethodCallExpression express)
95+
{
96+
var methodName = express.Method.Name;
97+
return methodName == nameof(string.StartsWith)&& (express.Method.DeclaringType==typeof(string));
98+
}
99+
public static bool IsStringEndWith(this MethodCallExpression express)
100+
{
101+
var methodName = express.Method.Name;
102+
return methodName == nameof(string.EndsWith)&& (express.Method.DeclaringType==typeof(string));
88103
}
89104
/// <summary>
90105
/// 是否是equal方法

src/ShardingCore/Extensions/LinqExtension.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ public static bool IsNotEmpty<T>(this IEnumerable<T> source)
4747
{
4848
return !source.IsEmpty();
4949
}
50-
public static bool IsIn<T>(this T thisValue, params T[] values)
50+
51+
private static readonly HashSet<string> _enumerableContainsNamespace = new HashSet<string>()
52+
{
53+
"System.Linq", "System.Collections.Generic"
54+
};
55+
public static bool IsInEnumerable(this string thisValue)
5156
{
52-
return values.Contains(thisValue);
57+
return _enumerableContainsNamespace.Contains(thisValue);
5358
}
5459
/// <summary>
5560
/// 按size分区,每个区size个数目

src/ShardingCore/Sharding/Visitors/QueryableRouteDiscoverVisitor.cs

Lines changed: 242 additions & 125 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)