/// <summary> /// Checks the value of the supplied <see cref="ICollection"/> <paramref name="argument"/> and throws /// an <see cref="ArgumentException"/> if it is <see langword="null"/>, contains no elements or only null elements. /// </summary> /// <param name="argument">The array or collection to check.</param> /// <param name="name">The argument name.</param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="argument"/> is <see langword="null"/>, /// contains no elements or only null elements. /// </exception> public static void ArgumentHasElements(ICollection argument, string name) { if (!ArrayUtils.HasElements(argument)) { ThrowArgumentException( name, $"Argument '{name}' must not be null or resolve to an empty collection and must contain non-null elements"); } }
/// <summary> /// Checks the value of the supplied <see cref="ICollection"/> <paramref name="argument"/> and throws /// an <see cref="ArgumentException"/> if it is <see langword="null"/>, contains no elements or only null elements. /// </summary> /// <param name="argument">The array or collection to check.</param> /// <param name="name">The argument name.</param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="argument"/> is <see langword="null"/>, /// contains no elements or only null elements. /// </exception> public static void ArgumentHasElements(ICollection argument, string name) { if (!ArrayUtils.HasElements(argument)) { throw new ArgumentException( name, string.Format( CultureInfo.InvariantCulture, "Argument '{0}' must not be null or resolve to an empty collection and must contain non-null elements", name)); } }
/// <summary> /// Checks if the given array or collection has elements and none of the elements is null. /// </summary> /// <param name="collection">the collection to be checked.</param> /// <returns>true if the collection has a length and contains only non-null elements.</returns> public static bool HasElements(ICollection collection) { return(ArrayUtils.HasElements(collection)); }