Skip to content

Add GetValueOrNull on IDictionary<,> and IReadOnlyDictionary<,> for struct values - #80

Merged
Tyrrrz merged 6 commits into
primefrom
copilot/add-getvalueornull-method
Apr 22, 2026
Merged

Add GetValueOrNull on IDictionary<,> and IReadOnlyDictionary<,> for struct values#80
Tyrrrz merged 6 commits into
primefrom
copilot/add-getvalueornull-method

Conversation

Copilot AI commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Adds GetValueOrNull extension methods for generic dictionary interfaces constrained to where TValue : struct, returning TValue? instead of default(TValue) — the nullable counterpart to GetValueOrDefault.

  • IDictionary<TKey, TValue> — available on all target frameworks
  • IReadOnlyDictionary<TKey, TValue> — guarded with #if NET40_OR_GREATER || NETSTANDARD || NET (not available in net35)
IDictionary<string, int> dict = new Dictionary<string, int> { ["a"] = 1 };

int? found    = dict.GetValueOrNull("a");  // 1
int? notFound = dict.GetValueOrNull("z");  // null

Copilot AI and others added 2 commits April 22, 2026 10:30
…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>
Comment thread PowerKit/Extensions/DictionaryExtensions.cs Outdated
Comment thread PowerKit.Tests/Extensions/DictionaryExtensionsTests.cs Outdated
Comment thread PowerKit.Tests/Extensions/DictionaryExtensionsTests.cs Outdated
Copilot AI requested a review from Tyrrrz April 22, 2026 10:50
@Tyrrrz
Tyrrrz marked this pull request as ready for review April 22, 2026 11:07
Copilot AI review requested due to automatic review settings April 22, 2026 11:07
@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.85%. Comparing base (76a2635) to head (7ef1d83).
⚠️ Report is 1 commits behind head on prime.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetValueOrNull for IDictionary<TKey, TValue> where TValue : struct.
  • Add GetValueOrNull for IReadOnlyDictionary<TKey, TValue> where TValue : 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.

Comment thread PowerKit/Extensions/ReadOnlyDictionaryExtensions.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Tyrrrz
Tyrrrz merged commit 9e825ee into prime Apr 22, 2026
7 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/add-getvalueornull-method branch April 22, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants