Skip to content

Commit 5116b03

Browse files
authored
Add cast from IDictionary to ConcurrentDictionary (#9810)
1 parent b5e2bfc commit 5116b03

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Files.Shared/Extensions/LinqExtensions.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Threading.Tasks;
@@ -53,7 +54,14 @@ public static class LinqExtensions
5354
var defaultValue = defaultValueFunc();
5455
if (defaultValue is Task<TValue?> value)
5556
{
56-
dictionary.Add(key, value);
57+
if (dictionary is ConcurrentDictionary<TKey, Task<TValue?>> cDict)
58+
{
59+
cDict.TryAdd(key, value);
60+
}
61+
else
62+
{
63+
dictionary.Add(key, value);
64+
}
5765
}
5866
return defaultValue;
5967
}

0 commit comments

Comments
 (0)