Radarr/src/NzbDrone.Common/EnsureThat/EnsureCollectionExtensions.cs

80 lines
2.6 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using NzbDrone.Common.EnsureThat.Resources;
namespace NzbDrone.Common.EnsureThat
{
public static class EnsureCollectionExtensions
{
[DebuggerStepThrough]
2019-12-22 22:08:53 +00:00
public static Param<T> HasItems<T>(this Param<T> param)
where T : class, ICollection
{
if (param.Value == null || param.Value.Count < 1)
2019-12-22 22:08:53 +00:00
{
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
2019-12-22 22:08:53 +00:00
}
return param;
}
[DebuggerStepThrough]
public static Param<Collection<T>> HasItems<T>(this Param<Collection<T>> param)
{
if (param.Value == null || param.Value.Count < 1)
2019-12-22 22:08:53 +00:00
{
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
2019-12-22 22:08:53 +00:00
}
return param;
}
[DebuggerStepThrough]
public static Param<IEnumerable<T>> HasItems<T>(this Param<IEnumerable<T>> param)
{
if (param.Value == null || !param.Value.Any())
2019-12-22 22:08:53 +00:00
{
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
2019-12-22 22:08:53 +00:00
}
return param;
}
[DebuggerStepThrough]
public static Param<T[]> HasItems<T>(this Param<T[]> param)
{
if (param.Value == null || param.Value.Length < 1)
2019-12-22 22:08:53 +00:00
{
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
2019-12-22 22:08:53 +00:00
}
return param;
}
[DebuggerStepThrough]
public static Param<List<T>> HasItems<T>(this Param<List<T>> param)
{
if (param.Value == null || param.Value.Count < 1)
2019-12-22 22:08:53 +00:00
{
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
2019-12-22 22:08:53 +00:00
}
return param;
}
[DebuggerStepThrough]
public static Param<IDictionary<TKey, TValue>> HasItems<TKey, TValue>(this Param<IDictionary<TKey, TValue>> param)
{
if (param.Value == null || param.Value.Count < 1)
2019-12-22 22:08:53 +00:00
{
throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
2019-12-22 22:08:53 +00:00
}
return param;
}
}
2019-12-22 21:24:10 +00:00
}