Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
added null arg guard checks for linq extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sbohlen committed Jan 24, 2011
1 parent a03dcab commit 72fe12b
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ internal static class LinqExtensionMethods
{
public static int Count<TSource>(this IEnumerable<TSource> source)
{
if (source == null) throw new ArgumentNullException("source");

int counter = 0;
foreach (TSource obj in source)
{
Expand All @@ -18,6 +20,8 @@ public static int Count<TSource>(this IEnumerable<TSource> source)

internal static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value) where TSource : class
{
if (source == null) throw new ArgumentNullException("source");

foreach (TSource obj in source)
{
if (obj == value)
Expand All @@ -31,13 +35,25 @@ internal static bool Contains<TSource>(this IEnumerable<TSource> source, TSource

internal static IEnumerable<TSource> AsEnumerable<TSource>(this IEnumerable<TSource> source)
{
return source.Where(delegate { return true; });
if (source == null) throw new ArgumentNullException("source");

IList<TSource> results = new List<TSource>();

foreach (TSource obj in source)
{
results.Add(obj);
}

return results;
}


internal static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source,
Predicate<TSource> predicate)
{
if (source == null) throw new ArgumentNullException("source");
if (predicate == null) throw new ArgumentNullException("predicate");

IList<TSource> matching = new List<TSource>();

foreach (TSource obj in source)
Expand All @@ -54,6 +70,9 @@ internal static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> so

internal static bool Any<TSource>(this IEnumerable<TSource> source, Predicate<TSource> predicate)
{
if (source == null) throw new ArgumentNullException("source");
if (predicate == null) throw new ArgumentNullException("predicate");

foreach (TSource obj in source)
{
if (predicate(obj))
Expand Down

0 comments on commit 72fe12b

Please sign in to comment.