mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-22 23:21:28 +00:00
Store XML serializers in ConcurrentDictionary for thread safety
This commit is contained in:
parent
767f6271f2
commit
2372dfbb9e
1 changed files with 3 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -16,8 +17,7 @@ namespace LBPUnion.ProjectLighthouse.Serialization;
|
||||||
|
|
||||||
public static class LighthouseSerializer
|
public static class LighthouseSerializer
|
||||||
{
|
{
|
||||||
|
private static readonly ConcurrentDictionary<(Type, XmlRootAttribute?), CustomXmlSerializer> serializerCache = new();
|
||||||
private static readonly Dictionary<(Type, XmlRootAttribute?), CustomXmlSerializer> serializerCache = new();
|
|
||||||
|
|
||||||
private static readonly XmlSerializerNamespaces emptyNamespace = new(new[]
|
private static readonly XmlSerializerNamespaces emptyNamespace = new(new[]
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ public static class LighthouseSerializer
|
||||||
|
|
||||||
CustomXmlSerializer serializer = new(type, rootAttribute);
|
CustomXmlSerializer serializer = new(type, rootAttribute);
|
||||||
|
|
||||||
serializerCache.Add((type, rootAttribute), serializer);
|
serializerCache.TryAdd((type, rootAttribute), serializer);
|
||||||
return serializer;
|
return serializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue