Merged
Conversation
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request implements the MustHaveLength assertion for ImmutableArray<T> to avoid boxing when checking array lengths, providing better performance compared to generic IEnumerable<T> assertions.
- Adds two
MustHaveLengthextension methods forImmutableArray<T>with default and custom exception handling - Introduces
InvalidImmutableArrayLengthexception factory method for descriptive error messages - Creates comprehensive unit tests covering valid/invalid lengths, custom exceptions, and edge cases
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| issue-117-must-have-length-for-immutable-array.md | Documentation outlining implementation requirements and context |
| Throw.ImmutableArray.cs | New exception factory method for immutable array length validation |
| Check.MustHaveLength.cs | Two new extension methods implementing the MustHaveLength assertion |
| MustHaveLengthTests.cs | Comprehensive unit tests validating the new assertion functionality |
Code/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthTests.cs
Show resolved
Hide resolved
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 #117
This pull request introduces a new
MustHaveLengthassertion forImmutableArray<T>to the Light.GuardClauses library. The changes include the implementation of the assertion, the corresponding exception handling, and unit tests to validate the functionality. Additionally, documentation has been added to describe the context and tasks associated with this enhancement.New Assertion for
ImmutableArray<T>:Implementation of
MustHaveLengthmethods: Added two extension methods to theCheckclass inCheck.MustHaveLength.csto validate the length ofImmutableArray<T>. One method throws the defaultInvalidCollectionCountException, while the other allows custom exceptions via a delegate.Exception handling: Introduced
InvalidImmutableArrayLengthinThrow.ImmutableArray.csto handle invalid lengths forImmutableArray<T>. This method ensures descriptive error messages and integrates seamlessly with the new assertion.Unit Tests:
MustHaveLengthTests.csto verify the behavior of theMustHaveLengthassertion under various scenarios, including valid lengths, invalid lengths, custom exceptions, and default arrays.Documentation:
issue-117-must-have-length-for-immutable-array.mdto document the context, tasks, and implementation details for the newMustHaveLengthassertion. This file provides a clear guide for understanding the purpose and design of the feature.