Open
Description
Analyzer
Diagnostic ID: CA1854
Describe the improvement
CA1854 is a nice performance analyzer that can help avoid duplicate work on dictionary access. We ran into a case recently where it didn't trigger on some code and a community member helpfully noticed and fixed our code to use TryGetValue
. The screenshot below shows 3 examples, the working example and then code similar to what we had where the analyzer didn't trigger, and then finally an even simpler example that's likely the root cause of what the analyzer isn't finding.
Describe suggestions on how to achieve the rule
I'm not an analyzer expert, but it seems like any &&
(or ||
) operation could be looked at for finding this pattern.
Additional context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment