Use TryGetValue() for dictionary lookup by martincostello · Pull Request #44791 · dotnet/aspnetcore (original) (raw)
Use TryGetValue
Use TryGetValue()
instead of ContainsKey()
and the indexer.
Description
While looking through the Identity code to work out why something I'm doing wasn't working, I spotted a case where TryGetValue()
wasn't being used to access a dictionary value. I did a quick search and found a couple more, but I didn't go through the whole repo so there might be more lurking.
Enabling the new CA1854 rule would surface more of this and help stop new ones being added.