/// <summary> /// Projects each element of a sequence into a new form. /// </summary> /// <typeparam name="TSource">The type of the elements of source.</typeparam> /// <typeparam name="TResult">The type of the value returned by selector.</typeparam> /// <param name="source">A sequence of values to invoke a transform function on.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <returns>An <see cref="IEnumerable<T>"/> whose elements are the result of invoking the transform function on each element of source..</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> or <paramref name="selector"/> argument is null.</exception> internal static IEnumerable <TResult> Select <TSource, TResult>(this IEnumerable <TSource> source, Func <TSource, TResult> selector) { if (null == source) { throw new ArgumentNullException("source"); } else if (null == selector) { throw new ArgumentNullException("selector"); } // Project each item in a separate method or null checks above are compiled away. return(ExtensionMethods.SelectIterator(source, selector)); }
/// <summary> /// Reeturns the sum of the field selected from each item in the source enumerable. /// </summary> /// <typeparam name="TSource">The type of the elements of source.</typeparam> /// <param name="source">A sequence of values from which fields are selected to sum.</param> /// <param name="selector">A transform function to apply to each element to get the field to sum.</param> /// <returns>The sum of the field selected from each item in the source enumerable.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> or <paramref name="selector"/> argument is null.</exception> internal static long Sum <TSource>(this IEnumerable <TSource> source, Func <TSource, long> selector) { if (null == source) { throw new ArgumentNullException("source"); } else if (null == selector) { throw new ArgumentNullException("selector"); } var sum = 0L; foreach (long i in ExtensionMethods.SelectIterator(source, selector)) { sum += i; } return(sum); }