Example #1
0
        /// <summary>
        /// Throws an <see cref="ArgumentNullException" /> if <paramref name="guardClause.Value" /> is null.
        /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is an empty enumerable.
        /// </summary>
        /// <param name="guardClause"></param>
        /// <param name="parameterName"></param>
        /// <returns><paramref name="guardClause" /> if the value is not an empty enumerable or null.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public static IGuard <IEnumerable <T> > AgainstNullOrEmpty <T>([NotNull, JetBrainsNotNull] this IGuard <IEnumerable <T> > guardClause, [NotNull, JetBrainsNotNull] string parameterName)
        {
            guardClause.AgainstNull(parameterName);
            if (!guardClause.Value.Any())
            {
                throw new ArgumentException($"Required input {parameterName} was empty.", parameterName);
            }

            return(guardClause);
        }
Example #2
0
        /// <summary>
        /// Throws an <see cref="ArgumentNullException" /> if <paramref name="guardClause.Value" /> is null.
        /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is an empty string.
        /// </summary>
        /// <param name="guardClause"></param>
        /// <param name="parameterName"></param>
        /// <returns><paramref name="guardClause" /> if the value is not an empty string or null.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public static IGuard <string> AgainstNullOrEmpty([NotNull, JetBrainsNotNull] this IGuard <string> guardClause, [NotNull, JetBrainsNotNull] string parameterName)
        {
            guardClause.AgainstNull(parameterName);
            if (guardClause.Value == string.Empty)
            {
                throw new ArgumentException($"Required input {parameterName} was empty.", parameterName);
            }

            return(guardClause);
        }
Example #3
0
 /// <summary>
 /// Throws an <see cref="ArgumentNullException" /> if <paramref name="guardClause.Value" /> is null.
 /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is an empty guid.
 /// </summary>
 /// <param name="guardClause"></param>
 /// <param name="parameterName"></param>
 /// <returns><paramref name="guardClause" /> if the value is not an empty guid or null.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 public static IGuard <Guid> AgainstNullOrEmpty([NotNull, JetBrainsNotNull] this IGuard <Guid?> guardClause, [NotNull, JetBrainsNotNull] string parameterName)
 {
     guardClause.AgainstNull(parameterName);
     return(Guard.WithValue(guardClause.Value !.Value).AgainstEmpty(parameterName));
 }