File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed
Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 11using System ;
2+ using System . Collections . Concurrent ;
23using System . Collections . Generic ;
34using System . Linq ;
45using System . Reflection ;
@@ -15,33 +16,32 @@ public Query AsUpdate(object data)
1516 return AsUpdate ( dictionary ) ;
1617 }
1718
18-
19- private static Dictionary < Type , List < PropertyInfo > > CacheDictionaryProperties = new Dictionary < Type , List < PropertyInfo > > ( ) ;
20-
19+ private static readonly ConcurrentDictionary < Type , PropertyInfo [ ] > CacheDictionaryProperties = new ConcurrentDictionary < Type , PropertyInfo [ ] > ( ) ;
2120
2221 private Dictionary < string , object > BuildDictionaryOnUpdate ( object data )
2322 {
24-
2523 var dictionary = new Dictionary < string , object > ( ) ;
26- var props = data . GetType ( ) . GetRuntimeProperties ( ) ;
24+ var props = CacheDictionaryProperties . GetOrAdd ( data . GetType ( ) , type => type . GetRuntimeProperties ( ) . ToArray ( ) ) ;
2725
2826 foreach ( PropertyInfo property in props )
2927 {
30- if ( property . GetCustomAttribute ( typeof ( IgnoreAttribute ) ) != null ) {
28+ if ( property . GetCustomAttribute ( typeof ( IgnoreAttribute ) ) != null )
29+ {
3130 continue ;
3231 }
3332
3433 var value = property . GetValue ( data ) ;
3534
3635 var colAttr = property . GetCustomAttribute ( typeof ( ColumnAttribute ) ) as ColumnAttribute ;
3736 var name = colAttr ? . Name ?? property . Name ;
38- if ( colAttr != null )
37+ if ( colAttr != null )
3938 {
40- if ( ( colAttr as KeyAttribute ) != null )
39+ if ( ( colAttr as KeyAttribute ) != null )
4140 {
4241 this . Where ( name , value ) ;
4342 }
44- }
43+ }
44+
4545 dictionary . Add ( name , value ) ;
4646 }
4747
Original file line number Diff line number Diff line change 77 <Description >A powerful Dynamic Sql Query Builder supporting Sql Server, MySql, PostgreSql and Firebird</Description >
88 <Authors >Ahmad Moussawi</Authors >
99 <Copyright >Copyright (c) 2017 Ahmad Moussawi</Copyright >
10- <TargetFrameworks >netstandard1.0;net45 </TargetFrameworks >
10+ <TargetFrameworks >net45; netstandard1.1 </TargetFrameworks >
1111 <RootNamespace >SqlKata</RootNamespace >
1212 </PropertyGroup >
13+ <ItemGroup >
14+ <PackageReference Include =" System.Collections.Concurrent" Version =" 4.3.0" />
15+ </ItemGroup >
1316</Project >
You can’t perform that action at this time.
0 commit comments