Skip to content

Commit

Permalink
Reintroduced XmlSerializerCodec fix. Which was mistakenly removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbra-mak committed Jan 20, 2023
1 parent 4a838e0 commit 7806d2d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Ramone/MediaTypes/Xml/XmlSerializerCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
using System.Xml.Serialization;
using System;
using System.Collections.Generic;

using System.Collections.Concurrent;

namespace Ramone.MediaTypes.Xml
{
public class XmlSerializerCodec : XmlStreamCodecBase
{
// The XmlSerializer is thread safe according to the online docs, so it should be safe
// to share instances.
static Dictionary<Type, XmlSerializer> Serializers { get; set; }
static ConcurrentDictionary<Type, XmlSerializer> Serializers { get; set; }


static XmlSerializerCodec()
{
Serializers = new Dictionary<Type, XmlSerializer>();
Serializers = new ConcurrentDictionary<Type, XmlSerializer>();
}


Expand All @@ -38,11 +38,7 @@ protected override void WriteTo(object item, XmlWriter writer, WriterContext con

protected XmlSerializer GetSerializer(Type t)
{
if (!Serializers.ContainsKey(t))
{
Serializers[t] = CreateSerializer(t);
}
return Serializers[t];
return Serializers.GetOrAdd(t, CreateSerializer);
}


Expand Down

0 comments on commit 7806d2d

Please sign in to comment.