Skip to content

Commit 529ffac

Browse files
committed
Revert "Use TryAdd()"
This reverts commit 42783c0.
1 parent 42783c0 commit 529ffac

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Files.Shared/Extensions/LinqExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class LinqExtensions
3333
if (!dictionary.ContainsKey(key))
3434
{
3535
if (defaultValue is TValue value)
36-
dictionary.TryAdd(key, value);
36+
dictionary.Add(key, value);
3737

3838
return defaultValue;
3939
}
@@ -53,8 +53,16 @@ public static class LinqExtensions
5353
{
5454
var defaultValue = defaultValueFunc();
5555
if (defaultValue is Task<TValue?> value)
56-
dictionary.TryAdd(key, value);
57-
56+
{
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+
}
65+
}
5866
return defaultValue;
5967
}
6068
return dictionary[key];

0 commit comments

Comments
 (0)