Dictionary Keys Guards - #150
Merged
Merged
Conversation
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reintroduces dictionary key guard clauses (MustContainKey / MustNotContainKey) to Light.GuardClauses using the v4-era conventions, including new exception types, throw helpers, source-export support, documentation, and test coverage.
Changes:
- Added
MustContainKey/MustNotContainKeyguards forIReadOnlyDictionary<TKey, TValue>plus shape-preserving overloads forDictionary<TKey, TValue>. - Introduced
MissingKeyException/ExistingKeyExceptionand correspondingThrow.MissingKey/Throw.ExistingKeyhelpers. - Updated source-export whitelists/settings, regenerated the .NET Standard single-file distribution, expanded docs, and added comprehensive automated tests.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/source-export/Light.GuardClauses.SourceCodeTransformation/settings.json | Adds the new assertion families to the source-export configuration. |
| tools/source-export/Light.GuardClauses.SourceCodeTransformation/AssertionWhitelist.cs | Extends the whitelist model with MustContainKey / MustNotContainKey entries. |
| src/Light.GuardClauses/Check.MustContainKey.cs | Implements MustContainKey guards for IReadOnlyDictionary and Dictionary (shape-preserving) with factory overloads. |
| src/Light.GuardClauses/Check.MustNotContainKey.cs | Implements MustNotContainKey guards for IReadOnlyDictionary and Dictionary (shape-preserving) with factory overloads. |
| src/Light.GuardClauses/Exceptions/MissingKeyException.cs | Adds the new exception type thrown when a key is missing. |
| src/Light.GuardClauses/Exceptions/ExistingKeyException.cs | Adds the new exception type thrown when a key unexpectedly exists. |
| src/Light.GuardClauses/ExceptionFactory/Throw.MissingKey.cs | Provides the default exception construction/message for missing-key failures (including key listing). |
| src/Light.GuardClauses/ExceptionFactory/Throw.ExistingKey.cs | Provides the default exception construction/message for existing-key failures. |
| tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainKeyTests.cs | Adds behavioral, null-handling, comparer-sensitivity, factory, message, and binding tests for MustContainKey. |
| tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainKeyTests.cs | Adds behavioral, null-handling, comparer-sensitivity, factory, message, and binding tests for MustNotContainKey. |
| tests/Light.GuardClauses.SourceCodeTransformation.Tests/SourceFileMergerWhitelistTests.cs | Verifies source-export whitelist output includes the new guards/exceptions/throw helpers and trims factory overloads when disabled. |
| Light.GuardClauses.SingleFile.cs | Regenerates the .NET Standard single-file distribution to include the new guards and exceptions. |
| docs/assertion-overview.md | Documents the new dictionary key guards and the IDictionary<TKey, TValue> limitation/workaround. |
| ai-plans/0148-dictionary-key-guards.md | Adds the implementation plan/acceptance criteria record for issue #148. |
| AGENTS.md | Removes a previously recorded “notes” entry from the “Here is Your Space” section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Closes #148