Skip to content

Commit

Permalink
♻️ (Guard.Collection) ICollection replaced by IEnumerable<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
maiconheck committed Dec 19, 2020
1 parent 31bfec1 commit 5ba714d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Krafted/Directory.build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<Authors>Maicon Heck</Authors>
<Version>3.0.0</Version>
<PackageVersion>3.0.0</PackageVersion>
<Version>3.1.0</Version>
<PackageVersion>3.1.0</PackageVersion>
<Product>Krafted</Product>
<ProductName>Krafted</ProductName>
<PackageId>$(MSBuildProjectName)</PackageId>
Expand Down
13 changes: 8 additions & 5 deletions src/Krafted/Krafted.Guards/Guard.Collection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Krafted.Guards
{
Expand All @@ -14,17 +15,18 @@ public partial class Guard
/// Throws an <see cref="ArgumentException"/> if the <c>collection</c> is empty,
/// with this error message: Collection cannot be empty.
/// </summary>
/// <typeparam name="T">The type of enumerable.</typeparam>
/// <param name="collection">The parameter to check.</param>
/// <param name="parameterName">The name of the parameter.</param>
/// <returns>The guard.</returns>
/// <exception cref="ArgumentException">.</exception>
public Guard Empty(ICollection collection, string parameterName)
public Guard Empty<T>(IEnumerable<T> collection, string parameterName)
{
Guard.Against.
Null(collection, nameof(collection)).
NullOrWhiteSpace(parameterName, nameof(parameterName));

if (collection.Count == 0)
if (!collection.Any())
throw new ArgumentException(Texts.CollectionCannotBeEmpty, parameterName);

return this;
Expand All @@ -34,17 +36,18 @@ public Guard Empty(ICollection collection, string parameterName)
/// Throws an <see cref="ArgumentException"/> if the <c>collection</c> is not empty,
/// with this error message: Collection should be empty.
/// </summary>
/// <typeparam name="T">The type of enumerable.</typeparam>
/// <param name="collection">The parameter to check.</param>
/// <param name="parameterName">The name of the parameter.</param>
/// <returns>The guard.</returns>
/// <exception cref="ArgumentException">.</exception>
public Guard NotEmpty(ICollection collection, string parameterName)
public Guard NotEmpty<T>(IEnumerable<T> collection, string parameterName)
{
Guard.Against.
Null(collection, nameof(collection)).
NullOrWhiteSpace(parameterName, nameof(parameterName));

if (collection.Count > 0)
if (collection.Any())
throw new ArgumentException(Texts.CollectionShouldBeEmpty, parameterName);

return this;
Expand Down

0 comments on commit 5ba714d

Please sign in to comment.