Skip to content

Commit

Permalink
Can use nameof expression directly to get the data type name (#67)
Browse files Browse the repository at this point in the history
* Can use nameof expression directly to get the data type name

* The 'notnull' constraint is redundant because type parameter 'TValue' is constrained by non-nullable type 'IEnumerable'

* The 'notnull' constraint is redundant because type parameter 'TValue' is constrained by non-nullable type 'IEnumerable'
  • Loading branch information
nirzaf committed Apr 26, 2023
1 parent 719a1cb commit 104457d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/Validators/Validator.Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static void ThrowIfCountNot<TValue>(
string paramName,
ExceptionCustomizations? exceptionCustomizations,
string? message = null)
where TValue : notnull, IEnumerable
where TValue : IEnumerable
{
if (GetCollectionCount(value) != count)
{
Expand All @@ -27,7 +27,7 @@ internal static void ThrowIfCount<TValue>(
string paramName,
ExceptionCustomizations? exceptionCustomizations,
string? message = null)
where TValue : notnull, IEnumerable
where TValue : IEnumerable
{
if (GetCollectionCount(value) == count)
{
Expand All @@ -44,7 +44,7 @@ internal static void ThrowIfCountGreaterThan<TValue>(
int count,
string paramName,
ExceptionCustomizations? exceptionCustomizations)
where TValue : notnull, IEnumerable
where TValue : IEnumerable
{
if (GetCollectionCount(value) > count)
{
Expand Down Expand Up @@ -77,7 +77,7 @@ internal static void ThrowIfHasNullElements<TValue>(
TValue value,
string paramName,
ExceptionCustomizations? exceptionCustomizations)
where TValue : notnull, IEnumerable
where TValue : IEnumerable
{
foreach (object? item in value)
{
Expand All @@ -97,7 +97,7 @@ internal static void ThrowIfContainsElement<TValue, TElement>(
TElement element,
string paramName,
ExceptionCustomizations? exceptionCustomizations)
where TValue : notnull, IEnumerable<TElement?>
where TValue : IEnumerable<TElement?>
where TElement : notnull
{
if (IsElementInCollection(value, element))
Expand All @@ -115,7 +115,7 @@ internal static void ThrowIfNotContainsElement<TValue, TElement>(
TElement element,
string paramName,
ExceptionCustomizations? exceptionCustomizations)
where TValue : notnull, IEnumerable<TElement?>
where TValue : IEnumerable<TElement?>
where TElement : notnull
{
if (!IsElementInCollection(value, element))
Expand Down Expand Up @@ -144,7 +144,7 @@ internal static bool IsElementInCollection<TValue, TElement>(TValue value, TElem

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetCollectionCount<TValue>(TValue value)
where TValue : notnull, IEnumerable
where TValue : IEnumerable
{
static int GetEnumeratedCount(IEnumerable enumerable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void ThrowIfNotType_WhenCompileTimeTypeIsNotType_ShouldThrow()
// Assert
action.Should()
.ThrowExactly<ArgumentException>()
.WithMessage($"Parameter should be of type '{typeof(int).Name}'. (Parameter '{nameof(str)}')");
.WithMessage($"Parameter should be of type '{nameof(Int32)}'. (Parameter '{nameof(str)}')");
}

[TestMethod]
Expand Down

0 comments on commit 104457d

Please sign in to comment.