File tree Expand file tree Collapse file tree 1 file changed +3
-9
lines changed
Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Original file line number Diff line number Diff line change 11namespace Ecng . Serialization ;
22
3+ using System . Collections . Concurrent ;
34using System . Reflection ;
45
56using Ecng . Common ;
@@ -9,7 +10,7 @@ namespace Ecng.Serialization;
910/// </summary>
1011public static class SchemaRegistry
1112{
12- private static readonly Dictionary < Type , Schema > _cache = [ ] ;
13+ private static readonly ConcurrentDictionary < Type , Schema > _cache = [ ] ;
1314
1415 /// <summary>
1516 /// Registers a schema for the given entity type.
@@ -30,14 +31,7 @@ public static bool TryGet(Type entityType, out Schema meta)
3031 /// Gets the schema for the specified entity type, creating one via reflection if not registered.
3132 /// </summary>
3233 public static Schema Get ( Type entityType )
33- {
34- if ( _cache . TryGetValue ( entityType , out var meta ) )
35- return meta ;
36-
37- meta = CreateFromReflection ( entityType ) ;
38- _cache [ entityType ] = meta ;
39- return meta ;
40- }
34+ => _cache . GetOrAdd ( entityType , CreateFromReflection ) ;
4135
4236 private static Schema CreateFromReflection ( Type entityType )
4337 {
You can’t perform that action at this time.
0 commit comments