// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace E { public class Wrapper : IEnumerable { private List real; public Wrapper(List real) { this.real = real; } IEnumerator IEnumerable.GetEnumerator() { Console.WriteLine("IEnumerable.GetEnumerator"); return real.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { Console.WriteLine("IEnumerable.GetEnumerator"); return real.GetEnumerator(); } } public static class Fake { public static IEnumerable FakeWhere(this IEnumerable source, Func predicate) { Console.WriteLine("IEnumerable.Where"); return source.Where(predicate); } public static int FakeCount(this IEnumerable source) { Console.WriteLine("IEnumerable.Count"); return source.Count(); } } public class Program { public static void Main(string[] args) { List lst = new List { 1, 2, 3, 4, 5 }; Console.WriteLine(lst.Where(v => v > 2 && v < 5).Count()); Wrapper wrp = new Wrapper(lst); Console.WriteLine(wrp.FakeWhere(v => v > 2 && v < 5).FakeCount()); } } }