refactor: use trygetvalue for dictionary lookup#127
Merged
StuartFerguson merged 3 commits intomainfrom Sep 18, 2025
Merged
Conversation
This PR refactors dictionary access in the handler to use TryGetValue, reducing redundant lookups and improving readability and performance. - Consider using `.TryGetValue` to access elements in `Dictionary` The code originally checked for key existence with `ContainsKey` and then used the indexer to retrieve the value. This resulted in two lookups and less concise logic. By switching to `TryGetValue`, we combine the existence check and retrieval in a single operation, storing the result in a local variable and simplifying the conditional flow. > This Autofix was generated by AI. Please review the change before merging.
|
Here's the code health analysis summary for commits Analysis Summary
|
This PR refactors the conditional logic in the event handler by merging two nested `if` statements into a single combined check. The redundant inner block and braces have been removed, simplifying the code path and improving readability. - `if` conditions can be merged: The code originally checked for a handler key and then separately checked if the event type was present in the collection. These two nested `if` statements have been merged into one compound condition using a logical AND. As a result, the redundant block and braces are eliminated and the method now immediately returns true when both conditions are met. > This Autofix was generated by AI. Please review the change before merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors dictionary access in the handler to use TryGetValue, reducing redundant lookups and improving readability and performance.
.TryGetValueto access elements inDictionaryThe code originally checked for key existence with
ContainsKeyand then used the indexer to retrieve the value. This resulted in two lookups and less concise logic. By switching toTryGetValue, we combine the existence check and retrieval in a single operation, storing the result in a local variable and simplifying the conditional flow.