Skip to content

add CA1883: prefer Dictionary.Remove(key, out value) over TryGetValue followed by Remove - #57173

Open
lagudafuadtosin wants to merge 1 commit into
dotnet:mainfrom
lagudafuadtosin:ca1883-dictionary-remove-out
Open

lagudafuadtosin wants to merge 1 commit into
dotnet:mainfrom
lagudafuadtosin:ca1883-dictionary-remove-out

Conversation

@lagudafuadtosin

Copy link
Copy Markdown
Contributor

fixes dotnet/runtime#33800

added to DoNotGuardCallAnalyzer beside CA1853 and CA1868, with a C# code fix. reported only when Remove(key) comes straight after the TryGetValue check and the type has Remove(key, out value).

setup now skips an entry whose types are missing instead of returning, so projects without System.Collections.Immutable still get the rule.

tested: C# and VB tests, and a run over runtime's CoreLib and libraries: 4 hits, all correct.

@lagudafuadtosin
lagudafuadtosin requested a review from a team as a code owner November 17, 2026 13:34
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer Dictionary.Remove(key, out value) over Dictionary.this[key], followed by Dictionary.Remove(key)

2 participants