2020-05-01 19:05:28 +01:00
|
|
|
using System;
|
2020-05-02 21:48:21 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-05-01 19:05:28 +01:00
|
|
|
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Ensure input parameters
|
|
|
|
/// </summary>
|
|
|
|
internal static class Ensure
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Checks an argument to ensure it isn't null.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name = "value">The argument value to check</param>
|
|
|
|
/// <param name = "name">The name of the argument</param>
|
2020-05-03 21:34:03 +01:00
|
|
|
public static void ArgumentNotNull(object value, string name)
|
2020-05-01 19:05:28 +01:00
|
|
|
{
|
2020-05-02 12:04:26 +01:00
|
|
|
if (value != null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-05-01 19:05:28 +01:00
|
|
|
|
2020-05-03 21:34:03 +01:00
|
|
|
throw new ArgumentNullException(name);
|
2020-05-01 19:05:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks an argument to ensure it isn't null or an empty string
|
|
|
|
/// </summary>
|
|
|
|
/// <param name = "value">The argument value to check</param>
|
|
|
|
/// <param name = "name">The name of the argument</param>
|
|
|
|
public static void ArgumentNotNullOrEmptyString(string value, string name)
|
|
|
|
{
|
2020-05-02 12:04:26 +01:00
|
|
|
if (!string.IsNullOrEmpty(value))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-05-01 19:05:28 +01:00
|
|
|
|
|
|
|
throw new ArgumentException("String is empty or null", name);
|
|
|
|
}
|
2020-05-02 12:04:26 +01:00
|
|
|
|
2020-05-12 16:53:17 +01:00
|
|
|
public static void ArgumentNotNullOrEmptyList<T>(IEnumerable<T> value, string name)
|
2020-05-02 12:04:26 +01:00
|
|
|
{
|
2020-05-02 21:48:21 +01:00
|
|
|
if (value != null && value.Any())
|
2020-05-02 12:04:26 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-02 21:48:21 +01:00
|
|
|
throw new ArgumentException("List is empty or null", name);
|
2020-05-02 12:04:26 +01:00
|
|
|
}
|
2020-05-01 19:05:28 +01:00
|
|
|
}
|
|
|
|
}
|