Context
The .NET library Light.GuardClauses already has several assertions for collections. They often rely on IEnumerable<T> or IEnumerable. However, these assertions would result in ImmutableArray<T> being boxed - we want to avoid that by providing dedicated assertions for this type which avoids boxing. For this issue, we implement the MustHaveMinimumLength assertion for ImmutableArray<T>.
Tasks for this issue
Notes
- There are already plenty of other assertions and tests in this library. All overloads are placed in the same file in the production code project. The test projects has top-level folders for different groups of assertions, like
CollectionAssertions, StringAssertions, DateTimeAssertions and so on. Please take a look at them to follow a similar structure and code style.
- This assertion specifically targets
ImmutableArray<T> to avoid boxing that would occur with generic IEnumerable<T> extensions.
- Use the
Length property instead of Count as this is the appropriate property for ImmutableArray<T>.
- The assertion should verify that the
ImmutableArray<T> has at least the specified minimum length.
- If you have any questions or suggestions, please ask me about them.
Context
The .NET library Light.GuardClauses already has several assertions for collections. They often rely on
IEnumerable<T>orIEnumerable. However, these assertions would result inImmutableArray<T>being boxed - we want to avoid that by providing dedicated assertions for this type which avoids boxing. For this issue, we implement theMustHaveMinimumLengthassertion forImmutableArray<T>.Tasks for this issue
Check.MustHaveMinimumLength.csfile, but there is aCheck.MustHaveMinimumCount.csfile. Create a new file calledCheck.MustHaveMinimumLength.csin the root folder of the project.MustHaveMinimumLengthforImmutableArray<T>. It should be placed in the classCheckwhich is marked aspartial.parameterNameandmessagearguments and throw the default exception. The actual exception is thrown in theThrowclass - use the existingThrow.InvalidMinimumCollectionCountmethod which is located inExceptionFactory/Throw.InvalidMinimumCollectionCount.cs.Throw.CustomExceptionmethod and pass the delegate, the erroneousImmutableArray<T>instance and the minimum length.Lengthproperty ofImmutableArray<T>instead ofCountfor performance and correctness.Should()for assertions).Notes
CollectionAssertions,StringAssertions,DateTimeAssertionsand so on. Please take a look at them to follow a similar structure and code style.ImmutableArray<T>to avoid boxing that would occur with genericIEnumerable<T>extensions.Lengthproperty instead ofCountas this is the appropriate property forImmutableArray<T>.ImmutableArray<T>has at least the specified minimum length.