From 8d3decba673bd53d37d003924a896beaab871793 Mon Sep 17 00:00:00 2001 From: David Hall Date: Sat, 6 Jan 2018 16:35:14 -0700 Subject: [PATCH] Added All extension for IEnumerable on .NET 2 --- Core/BkwdComp/Linq.NET2.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Core/BkwdComp/Linq.NET2.cs b/Core/BkwdComp/Linq.NET2.cs index 96b1115f..1aebb845 100644 --- a/Core/BkwdComp/Linq.NET2.cs +++ b/Core/BkwdComp/Linq.NET2.cs @@ -7,6 +7,20 @@ namespace System.Linq /// Provides a set of static (Shared in Visual Basic) methods for querying objects that implement . public static class Enumerable { + /// Determines whether all elements of a sequence satisfy a condition. + /// The type of the elements of . + /// An whose elements to apply the predicate to. + /// A function to test each element for a condition. + /// true if all elements in the source sequence pass the test in the specified predicate; otherwise, false. + public static bool All(this IEnumerable source, Func predicate) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + if (predicate == null) throw new ArgumentNullException(nameof(predicate)); + foreach (TSource element in source) + if (!predicate(element)) return false; + return true; + } + /// Determines whether any element of a sequence satisfies a condition. /// The type of the elements of . /// An whose elements to apply the predicate to.