Skip to content

Commit c3d3e5b

Browse files
authored
Merge pull request #4 from luispelin/branch_emi_802
Branch emi 802
2 parents 5af80ad + 4b05549 commit c3d3e5b

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

Shared.DFe.Utils/FuncoesXml.cs

+26-23
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@
4141

4242
namespace DFe.Utils
4343
{
44-
public static class FuncoesXml
45-
{
46-
47-
// https://github.com/ZeusAutomacao/DFe.NET/issues/610
48-
private static readonly Hashtable CacheSerializers = new Hashtable();
49-
50-
/// <summary>
51-
/// Serializa a classe passada para uma string no form
52-
/// </summary>
53-
/// <typeparam name="T"></typeparam>
54-
/// <param name="objeto"></param>
55-
/// <returns></returns>
56-
public static string ClasseParaXmlString<T>(T objeto)
44+
public static class FuncoesXml
45+
{
46+
47+
// https://github.com/ZeusAutomacao/DFe.NET/issues/610
48+
private static readonly object _lock = new object();
49+
private static volatile Hashtable _cacheSerializers = new Hashtable();
50+
51+
/// <summary>
52+
/// Serializa a classe passada para uma string no form
53+
/// </summary>
54+
/// <typeparam name="T"></typeparam>
55+
/// <param name="objeto"></param>
56+
/// <returns></returns>
57+
public static string ClasseParaXmlString<T>(T objeto)
5758
{
5859
XElement xml;
5960
var keyNomeClasseEmUso = typeof(T).FullName;
@@ -224,16 +225,18 @@ public static string ObterNodeDeStringXml(string nomeDoNode, string stringXml)
224225
// https://github.com/ZeusAutomacao/DFe.NET/issues/610
225226
private static XmlSerializer BuscarNoCache(string chave, Type type)
226227
{
227-
if (CacheSerializers.Contains(chave))
228-
{
229-
return (XmlSerializer)CacheSerializers[chave];
230-
}
231-
232-
233-
var ser = XmlSerializer.FromTypes(new[] { type })[0];
234-
CacheSerializers.Add(chave, ser);
235-
236-
return ser;
228+
lock (_lock)
229+
{
230+
if (_cacheSerializers.Contains(chave))
231+
{
232+
return (XmlSerializer)_cacheSerializers[chave];
233+
}
234+
235+
var ser = XmlSerializer.FromTypes(new[] { type })[0];
236+
_cacheSerializers.Add(chave, ser);
237+
238+
return ser;
239+
}
237240
}
238241
}
239242
}

0 commit comments

Comments
 (0)