From 81b106a1bfc225abcee1c9b5cfad64489e8cb24b Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 10 Dec 2022 15:07:12 +0800 Subject: Develop secret api. v23 --- .../CrupestApi.Commons/Crud/TableInfo.cs | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs') 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 NonColumnProperties { get; } public IReadOnlyList ColumnNameList => _lazyColumnNameList.Value; - protected bool PropertyIsColumn(PropertyInfo property) + protected bool CheckPropertyIsColumn(PropertyInfo property) { var columnAttribute = property.GetCustomAttribute(); 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; + } } } } -- cgit v1.2.3