mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-05-28 08:58:37 +00:00
57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace Octokit
|
|
{
|
|
/// <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>
|
|
public static void ArgumentNotNull([ValidatedNotNull]object value, string name)
|
|
{
|
|
if (value != null) return;
|
|
|
|
throw new ArgumentNullException(name);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks a string argument to ensure it isn't null or empty.
|
|
/// </summary>
|
|
/// <param name = "value">The argument value to check</param>
|
|
/// <param name = "name">The name of the argument</param>
|
|
public static void ArgumentNotNullOrEmptyString([ValidatedNotNull]string value, string name)
|
|
{
|
|
ArgumentNotNull(value, name);
|
|
if (!string.IsNullOrWhiteSpace(value)) return;
|
|
|
|
throw new ArgumentException("String cannot be empty", name);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks a timespan argument to ensure it is a positive value.
|
|
/// </summary>
|
|
/// <param name = "value">The argument value to check</param>
|
|
/// <param name = "name">The name of the argument</param>
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public static void GreaterThanZero([ValidatedNotNull]TimeSpan value, string name)
|
|
{
|
|
ArgumentNotNull(value, name);
|
|
|
|
if (value.TotalMilliseconds > 0) return;
|
|
|
|
throw new ArgumentException("Timespan must be greater than zero", name);
|
|
}
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Parameter)]
|
|
internal sealed class ValidatedNotNullAttribute : Attribute
|
|
{
|
|
}
|
|
}
|