Skip to content

Commit 4a30d48

Browse files
Merge pull request #189 from avadev/jwenger100/fix-github-issues
Added concurrent dictionary to applicable .NET versions of the SDK
2 parents f8f89aa + 854b507 commit 4a30d48

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/AvaTaxOfflineHelper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using Newtonsoft.Json;
22
using System;
33
using System.Collections.Generic;
4+
#if !NET20
5+
using System.Collections.Concurrent;
6+
#endif
47
using System.IO;
58

69
namespace Avalara.AvaTax.RestClient
@@ -27,7 +30,12 @@ public static class AvaTaxOfflineHelper
2730
/// is the ZIP code for which you wish to retrieve a TaxRateModel, if
2831
/// it has been downloaded.
2932
/// </summary>
33+
#if NET20
3034
private static readonly Dictionary<string, TaxRateModel> _ratesByZip = new Dictionary<string, TaxRateModel>();
35+
#else
36+
private static readonly ConcurrentDictionary<string, TaxRateModel> _ratesByZip = new ConcurrentDictionary<string, TaxRateModel>();
37+
#endif
38+
3139

3240
/// <summary>
3341
/// Initializes a new instance of the <see cref="AvaTaxOfflineHelper"/> class.
@@ -90,7 +98,11 @@ public static TaxRateModel GetLocalTaxRateByZip(string zip, string path)
9098
if (_ratesByZip.ContainsKey(zip)) {
9199
zipRate = _ratesByZip[zip];
92100
} else if (VerifyLocalZipRateAvailable(zip, path)) {
101+
#if NET20
93102
_ratesByZip.Add(zip, ReadZipRateFile(zip, path));
103+
#else
104+
_ratesByZip.TryAdd(zip, ReadZipRateFile(zip, path));
105+
#endif
94106
zipRate = _ratesByZip[zip];
95107
}
96108

0 commit comments

Comments
 (0)