diff options
author | crupest <crupest@outlook.com> | 2022-12-10 15:07:12 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 |
commit | 81b106a1bfc225abcee1c9b5cfad64489e8cb24b (patch) | |
tree | e739a8e449a1fd021a3118d9ccfb277d3f02b062 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs | |
parent | 2c9e38fbb434759593825f3893563dcd0c3806bb (diff) | |
download | crupest-81b106a1bfc225abcee1c9b5cfad64489e8cb24b.tar.gz crupest-81b106a1bfc225abcee1c9b5cfad64489e8cb24b.tar.bz2 crupest-81b106a1bfc225abcee1c9b5cfad64489e8cb24b.zip |
Develop secret api. v23
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs index 9977465..28dc1ad 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs @@ -35,7 +35,7 @@ public class TableInfo foreach (var property in properties) { - if (PropertyIsColumn(property)) + if (CheckPropertyIsColumn(property)) { var columnInfo = new ColumnInfo(this, property, _columnTypeProvider); columnInfos.Add(columnInfo); @@ -89,7 +89,7 @@ public class TableInfo public IReadOnlyList<PropertyInfo> NonColumnProperties { get; } public IReadOnlyList<string> ColumnNameList => _lazyColumnNameList.Value; - protected bool PropertyIsColumn(PropertyInfo property) + protected bool CheckPropertyIsColumn(PropertyInfo property) { var columnAttribute = property.GetCustomAttribute<ColumnAttribute>(); if (columnAttribute is null) return false; @@ -469,17 +469,21 @@ public class TableInfoFactory : ITableInfoFactory _columnTypeProvider = columnTypeProvider; } + // This is thread-safe. public TableInfo Get(Type type) { - if (_cache.TryGetValue(type, out var tableInfo)) + lock (_cache) { - return tableInfo; - } - else - { - tableInfo = new TableInfo(type, _columnTypeProvider); - _cache.Add(type, tableInfo); - return tableInfo; + if (_cache.TryGetValue(type, out var tableInfo)) + { + return tableInfo; + } + else + { + tableInfo = new TableInfo(type, _columnTypeProvider); + _cache.Add(type, tableInfo); + return tableInfo; + } } } } |