Version Used:
3.0.0-beta2-19055-09
ConcurrentDictionary.AddOrUpdate is misused throughout the codebase. The anti-pattern seems to be:
ConcurrentDictionary<T1, T2> dictionary;
dictionary.AddOrUpdate(key, value, (_1, _2) => value);
The right usage would be:
ConcurrentDictionary<T1, T2> dictionary;
dictionary[key] = value;
More info on this is in this commit: https://github.com/dotnet/roslyn/pull/33173/commits/2ac11675a1785bdb58c54369f8a6cbb3c529d50e
@sharwell could we write an analyzer to catch this?
@mavasani too.
@CyrusNajmabadi Sure, but it should probably be implemented as an analyzer in dotnet/corefx or dotnet/coreclr since it's a framework usage analysis.
Opened issue to track ConcurrentDictionary analyzer: https://github.com/dotnet/roslyn-analyzers/issues/2274
Most helpful comment
@CyrusNajmabadi Sure, but it should probably be implemented as an analyzer in dotnet/corefx or dotnet/coreclr since it's a framework usage analysis.