1
- using System . Diagnostics . CodeAnalysis ;
1
+ using System . Collections . Concurrent ;
2
+ using System . Diagnostics . CodeAnalysis ;
2
3
using System . Linq . Expressions ;
3
4
4
5
namespace Cnblogs . Architecture . Ddd . Infrastructure . Abstractions ;
@@ -8,7 +9,7 @@ namespace Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
8
9
/// </summary>
9
10
public static class OrderBySegmentConfig
10
11
{
11
- private static readonly Dictionary < Type , Dictionary < string , OrderBySegment > > Cache = new ( ) ;
12
+ private static readonly ConcurrentDictionary < Type , ConcurrentDictionary < string , OrderBySegment > > Cache = new ( ) ;
12
13
13
14
/// <summary>
14
15
/// 注册新的可排序列。
@@ -24,7 +25,7 @@ public static void RegisterSortableProperty<TSource, TProperty>(
24
25
var sourceType = typeof ( TSource ) ;
25
26
if ( Cache . ContainsKey ( sourceType ) == false )
26
27
{
27
- Cache [ sourceType ] = new Dictionary < string , OrderBySegment > ( StringComparer . OrdinalIgnoreCase ) ;
28
+ Cache [ sourceType ] = new ConcurrentDictionary < string , OrderBySegment > ( StringComparer . OrdinalIgnoreCase ) ;
28
29
}
29
30
30
31
Cache [ sourceType ] [ name ] = new OrderBySegment ( false , exp ) ;
@@ -73,4 +74,24 @@ public static bool TryParseOrderBySegments<T>(
73
74
74
75
return segments . Count > 0 ;
75
76
}
76
- }
77
+ }
78
+
79
+ /// <summary>
80
+ /// 管理可排序列的映射。
81
+ /// </summary>
82
+ /// <typeparam name="TEntity">The entity to config.</typeparam>
83
+ public static class OrderBySegmentConfig < TEntity >
84
+ {
85
+ /// <summary>
86
+ /// 注册新的可排序列。
87
+ /// </summary>
88
+ /// <param name="name">列名。</param>
89
+ /// <param name="exp">属性表达式。</param>
90
+ /// <typeparam name="TProperty">属性类型。</typeparam>
91
+ public static void RegisterSortableProperty < TProperty > (
92
+ string name ,
93
+ Expression < Func < TEntity , TProperty > > exp )
94
+ {
95
+ OrderBySegmentConfig . RegisterSortableProperty ( name , exp ) ;
96
+ }
97
+ }
0 commit comments