pluralsight-linq-fundamentals/Queries/MyLInq.cs

28 lines
672 B
C#

using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Reflection;
namespace Queries
{
public static class MyLInq
{
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source,
Func<T, bool> predicate)
{
// define a customized filter extension for LINQ
// demonstrate how to create a customized LINQ filter
var result = new List<T>();
foreach (var item in source)
{
if (predicate(item))
{
result.Add(item);
}
}
return result;
}
}
}