-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add diagnostic for Dictionary.ContainsKey when used in an ? statement. #35854
Comments
ye, um it seems that issue before was moved there without recreating it, any way to do the same here as it seems to not let me move it there? |
@stephentoub @jeffhandley to help transfer the issue to runtime repo. |
Tagging subscribers to this area: @eiriktsarpalis |
Any updates on this one? |
Hi @AraHaan. Thanks for filing this suggestion. This has been tagged to be considered as a possible future analyzer that we could implement. We've already selected the analyzers we're investing in for .NET 5 though, so this is marked as Future. We will need to further review this analyzer concept before we can mark it as approved though, and I don't yet have a timeline for when we'll be reviewing the backlog for planning beyond .NET 5. If you would be interested in thinking through possible call site samples, showing those possible scenarios and edge cases, and illustrating with code snippets, that would help us though, and we then might even be able to mark this as up-for-grabs. Thanks! |
Isn't this a dup of #33798? |
oh shoot ye you are right it is possibly a duplicate. |
Closing as dup of #33798. |
Analyzer package
Microsoft.CodeAnalysis.FxCopAnalyzers
Package Version
v3.0.0 (Latest)
Diagnostic ID
None yet that I know of. I would like one added that lets users know that
Dictionary.ContainsKey(key) ? Dictionary[key] : null
is a double lookup and can be simplified toDictionary.TryGetKey(key, out var value) ? value : null
. Because of the lack of a diagnostic for this I did not know about it according to my usage on it.Repro steps
Expected behavior
A diagnostic for this that alerts the user of the possible performance hits from this example above.
Actual behavior
No diagnostic explaining all of this is reported. Probably because there is none yet that exists?
The text was updated successfully, but these errors were encountered: