Skip to content

Conversation

@feO2x
Copy link
Owner

@feO2x feO2x commented Jul 19, 2025

Closes #114

This pull request introduces a new assertion method, MustNotBeDefaultOrEmpty, for ImmutableArray<T> in the Light.GuardClauses library. The changes include the implementation of the assertion, unit tests, project file updates, and documentation for the new feature.

Implementation of MustNotBeDefaultOrEmpty for ImmutableArray<T>:

  • Code/Light.GuardClauses/Check.MustNotBeDefaultOrEmpty.cs: Added two overloads of the MustNotBeDefaultOrEmpty method to ensure that an ImmutableArray<T> is neither default nor empty. The first overload throws an EmptyCollectionException, while the second allows the caller to provide a custom exception.

Unit tests for the new assertion:

Project file updates:

Documentation for the new feature:

feO2x added 2 commits July 19, 2025 10:52
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
@feO2x feO2x self-assigned this Jul 19, 2025
@feO2x feO2x requested a review from Copilot July 19, 2025 09:06
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 PR implements a new assertion method MustNotBeDefaultOrEmpty for ImmutableArray<T> to avoid boxing that would occur when using existing collection assertions with IEnumerable<T>. The implementation follows the library's established patterns with two overloads - one using default exceptions and another allowing custom exception factories.

  • Added MustNotBeDefaultOrEmpty extension methods for ImmutableArray<T> with both standard and custom exception overloads
  • Created comprehensive unit tests covering default arrays, empty arrays, valid arrays, custom exceptions, and caller argument expressions
  • Added System.Collections.Immutable package reference to support the new functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Check.MustNotBeDefaultOrEmpty.cs Implements the two MustNotBeDefaultOrEmpty extension method overloads for ImmutableArray<T>
MustNotBeDefaultOrEmptyTests.cs Comprehensive unit tests for both overloads covering all edge cases
Light.GuardClauses.csproj Adds System.Collections.Immutable package reference and reorganizes existing package references
issue-114-must-not-be-default-or-empty-for-immutable-array.md Documentation outlining the implementation plan and requirements

Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
@feO2x feO2x merged commit e1484b4 into dev Jul 19, 2025
1 check passed
@feO2x feO2x deleted the issue-114-must-not-be-default-or-empty-for-immutable-array branch July 19, 2025 14:14
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.

Assertions for ImmutableArray<T>

2 participants