using System; using System.Diagnostics.CodeAnalysis; namespace Octokit { /// /// Ensure input parameters /// internal static class Ensure { /// /// Checks an argument to ensure it isn't null. /// /// The argument value to check /// The name of the argument public static void ArgumentNotNull([ValidatedNotNull]object value, string name) { if (value != null) return; throw new ArgumentNullException(name); } /// /// Checks a string argument to ensure it isn't null or empty. /// /// The argument value to check /// The name of the argument 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); } /// /// Checks a timespan argument to ensure it is a positive value. /// /// The argument value to check /// The name of the argument [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 { } }