Skip to content

Conversation

@feO2x
Copy link
Owner

@feO2x feO2x commented Jul 20, 2025

Closes #117

This pull request introduces a new MustHaveLength assertion for ImmutableArray<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 MustHaveLength methods: Added two extension methods to the Check class in Check.MustHaveLength.cs to validate the length of ImmutableArray<T>. One method throws the default InvalidCollectionCountException, while the other allows custom exceptions via a delegate.

  • Exception handling: Introduced InvalidImmutableArrayLength in Throw.ImmutableArray.cs to handle invalid lengths for ImmutableArray<T>. This method ensures descriptive error messages and integrates seamlessly with the new assertion.

Unit Tests:

  • Validation tests: Created comprehensive unit tests in MustHaveLengthTests.cs to verify the behavior of the MustHaveLength assertion under various scenarios, including valid lengths, invalid lengths, custom exceptions, and default arrays.

Documentation:

  • Issue description: Added issue-117-must-have-length-for-immutable-array.md to document the context, tasks, and implementation details for the new MustHaveLength assertion. This file provides a clear guide for understanding the purpose and design of the feature.

@feO2x feO2x self-assigned this Jul 20, 2025
@feO2x feO2x requested a review from Copilot July 20, 2025 19:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 MustHaveLength extension methods for ImmutableArray<T> with default and custom exception handling
  • Introduces InvalidImmutableArrayLength exception 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

@feO2x feO2x merged commit b235afb into dev Jul 20, 2025
1 check passed
@feO2x feO2x deleted the issue-117-must-have-length-for-immutable-array branch July 20, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MustHaveLength for ImmutableArray

2 participants