Issue 118 must have length in for immutable array #124
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>.