diff --git a/Src/Newtonsoft.Json/Utilities/LinqBridge.cs b/Src/Newtonsoft.Json/Utilities/LinqBridge.cs index 15beffe7..786a547b 100644 --- a/Src/Newtonsoft.Json/Utilities/LinqBridge.cs +++ b/Src/Newtonsoft.Json/Utilities/LinqBridge.cs @@ -158,11 +158,20 @@ namespace Newtonsoft.Json.Utilities.LinqBridge this IEnumerable source, Func predicate) { + CheckNotNull(source, "source"); CheckNotNull(predicate, "predicate"); - return source.Where((item, i) => predicate(item)); + return WhereYield(source, predicate); } + private static IEnumerable WhereYield( + IEnumerable source, + Func predicate) + { + foreach (var item in source) + if (predicate(item)) + yield return item; + } /// /// Filters a sequence of values based on a predicate. /// Each element's index is used in the logic of the predicate function.