Fixed multithreading safety on JsonMapper
parent
fdef5cc1a7
commit
3e2e2d717c
|
@ -9,7 +9,7 @@
|
|||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<AssemblyVersion>0.1.0.0</AssemblyVersion>
|
||||
<FileVersion>0.1.0.0</FileVersion>
|
||||
<PackageVersion>1.2.1</PackageVersion>
|
||||
<PackageVersion>1.2.2</PackageVersion>
|
||||
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -54,7 +54,14 @@ namespace ln.json.mapping
|
|||
|
||||
|
||||
Dictionary<Type, JSONMapping> mappings = new Dictionary<Type, JSONMapping>();
|
||||
public virtual void Add(JSONMapping mapping) => mappings[mapping.TargetType] = mapping;
|
||||
|
||||
public virtual void Add(JSONMapping mapping)
|
||||
{
|
||||
lock (mappings)
|
||||
{
|
||||
mappings[mapping.TargetType] = mapping;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<Type, MappingFactory> mappingFactories = new Dictionary<Type, MappingFactory>();
|
||||
public virtual void AddMappingFactory(Type targetType, MappingFactory mappingFactory) => mappingFactories.Add(targetType, mappingFactory);
|
||||
|
@ -63,12 +70,16 @@ namespace ln.json.mapping
|
|||
|
||||
public virtual bool TryBuildRememberedMapping(Type nativeType,out JSONMapping mapping)
|
||||
{
|
||||
if (TryBuildMapping(nativeType, out mapping))
|
||||
lock (mappings)
|
||||
{
|
||||
mappings.Add(nativeType, mapping);
|
||||
return true;
|
||||
if (TryBuildMapping(nativeType, out mapping))
|
||||
{
|
||||
mappings.Add(nativeType, mapping);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public virtual bool TryBuildMapping(Type nativeType,out JSONMapping mapping)
|
||||
{
|
||||
|
@ -119,16 +130,19 @@ namespace ln.json.mapping
|
|||
|
||||
public virtual bool TryGetMapping(Type nativeType,out JSONMapping mapping)
|
||||
{
|
||||
if (mappings.TryGetValue(nativeType, out mapping))
|
||||
return true;
|
||||
lock (mappings)
|
||||
{
|
||||
if (mappings.TryGetValue(nativeType, out mapping))
|
||||
return true;
|
||||
|
||||
if (RequestCustomMapping(nativeType, out mapping))
|
||||
return true;
|
||||
if (RequestCustomMapping(nativeType, out mapping))
|
||||
return true;
|
||||
|
||||
if ((this != DefaultMapper) && DefaultMapper.TryGetMapping(nativeType, out mapping))
|
||||
return true;
|
||||
if ((this != DefaultMapper) && DefaultMapper.TryGetMapping(nativeType, out mapping))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue