Issue 118 must have length in for immutable array#124
Merged
Conversation
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements the MustHaveLengthIn assertion for ImmutableArray<T> to avoid boxing issues when using generic collection assertions. The implementation provides dedicated methods that use the Length property for optimal performance and follows the established patterns in the Light.GuardClauses library.
- Adds two overloads of
MustHaveLengthInforImmutableArray<T>(default exception and custom exception variants) - Creates a dedicated exception factory method for immutable array length validation
- Provides comprehensive unit tests covering valid/invalid ranges, custom exceptions, and caller argument expression validation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Code/Plans/issue-118-must-have-length-in-for-immutable-array.md | Documentation outlining implementation requirements and tasks |
| Code/Light.GuardClauses/ExceptionFactory/Throw.ImmutableArrayLengthNotInRange.cs | New exception factory method for immutable array length validation |
| Code/Light.GuardClauses/Check.MustHaveLengthIn.cs | Implementation of two MustHaveLengthIn overloads for ImmutableArray<T> |
| Code/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthInTests.cs | Comprehensive unit tests for the new assertion methods |
Code/Light.GuardClauses/ExceptionFactory/Throw.ImmutableArrayLengthNotInRange.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 #118
This pull request introduces the
MustHaveLengthInassertion forImmutableArray<T>to the Light.GuardClauses library. The changes include adding production code for the assertion, creating corresponding unit tests, and documenting the implementation details. The main goal is to provide dedicated assertions forImmutableArray<T>to avoid boxing and ensure optimal performance.New Assertion Implementation:
Code/Light.GuardClauses/Check.MustHaveLengthIn.cs: Added two overloads of theMustHaveLengthInmethod forImmutableArray<T>. One overload throws the defaultArgumentOutOfRangeException, while the other allows custom exceptions via a delegate. Both methods check if the array's length falls within a specifiedRange<int>using theLengthproperty.Code/Light.GuardClauses/ExceptionFactory/Throw.ImmutableArrayLengthNotInRange.cs: Introduced a helper method in theThrowclass to create and throw anArgumentOutOfRangeExceptionwhen theImmutableArray<T>length is outside the specified range.Unit Tests:
Code/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthInTests.cs: Added comprehensive tests for theMustHaveLengthInassertion, including cases for valid ranges, invalid ranges, custom exceptions, custom messages, and caller argument expression validation.Documentation:
Code/Plans/issue-118-must-have-length-in-for-immutable-array.md: Documented the implementation details and rationale for adding theMustHaveLengthInassertion, along with tasks and notes for developers.Minor Code Updates:
Code/Light.GuardClauses/Check.MustHaveLengthIn.cs: Updatedusingdirectives to includeSystem.Collections.Immutablefor working withImmutableArray<T>.