public static void NotNullOrEmpty()

in src/Microsoft.VisualStudio.Validation/Requires.cs [214:243]


        public static void NotNullOrEmpty<T>([ValidatedNotNull, NotNull] IEnumerable<T> values, string? parameterName)
        {
            // To whoever is doing random code cleaning:
            // Consider the performance when changing the code to delegate to NotNull.
            // In general do not chain call to another function, check first and return as earlier as possible.
            if (values is null)
            {
                throw new ArgumentNullException(parameterName);
            }

            bool isEmpty;
            if (values is ICollection<T> collection)
            {
                isEmpty = collection.Count == 0;
            }
            else if (values is IReadOnlyCollection<T> readOnlyCollection)
            {
                isEmpty = readOnlyCollection.Count == 0;
            }
            else
            {
                using IEnumerator<T> enumerator = values.GetEnumerator();
                isEmpty = !enumerator.MoveNext();
            }

            if (isEmpty)
            {
                throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
            }
        }