Add GetValueOrNull on IDictionary<,> and IReadOnlyDictionary<,> for struct values - #80
Merged
Merged
Conversation
…truct TValue Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/9c4b8ea4-27f3-4a79-a85f-a3feb7c644c6 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/9c4b8ea4-27f3-4a79-a85f-a3feb7c644c6 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Tyrrrz
April 22, 2026 10:37
View session
Tyrrrz
reviewed
Apr 22, 2026
Tyrrrz
reviewed
Apr 22, 2026
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/c363d2fa-4d03-4fc9-a5db-42fb307b288e Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/8e3a40cb-08a5-4517-97f3-5a42ccc66841 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Tyrrrz
reviewed
Apr 22, 2026
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/eb5b8adc-aa10-434f-bdba-5d7b945b322c Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Tyrrrz
approved these changes
Apr 22, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #80 +/- ##
==========================================
+ Coverage 93.83% 93.85% +0.02%
==========================================
Files 134 136 +2
Lines 2707 2717 +10
Branches 215 217 +2
==========================================
+ Hits 2540 2550 +10
Misses 123 123
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds nullable-returning dictionary lookup helpers for struct values, providing a clearer “missing key” signal than default(TValue) and aligning with existing “OrNull” patterns in PowerKit.
Changes:
- Add
GetValueOrNullforIDictionary<TKey, TValue>whereTValue : struct. - Add
GetValueOrNullforIReadOnlyDictionary<TKey, TValue>whereTValue : struct, guarded for non-net35 TFMs. - Add/extend unit tests covering found vs. missing key behavior for both interfaces.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| PowerKit/Extensions/ReadOnlyDictionaryExtensions.cs | New extension method for IReadOnlyDictionary<,> returning TValue? (TFM-guarded). |
| PowerKit/Extensions/DictionaryExtensions.cs | Adds GetValueOrNull for IDictionary<,> returning TValue?. |
| PowerKit.Tests/Extensions/ReadOnlyDictionaryExtensionsTests.cs | New tests for IReadOnlyDictionary<,>.GetValueOrNull. |
| PowerKit.Tests/Extensions/DictionaryExtensionsTests.cs | Adds tests for IDictionary<,>.GetValueOrNull. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced May 27, 2026
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.
Adds
GetValueOrNullextension methods for generic dictionary interfaces constrained towhere TValue : struct, returningTValue?instead ofdefault(TValue)— the nullable counterpart toGetValueOrDefault.IDictionary<TKey, TValue>— available on all target frameworksIReadOnlyDictionary<TKey, TValue>— guarded with#if NET40_OR_GREATER || NETSTANDARD || NET(not available in net35)