// Experiment with extension methods and C5, 2007-10-31 // Compile with // csc /r:C5.dll Extension.cs using System; using System.Linq.Expressions; using C5; using SCG = System.Collections.Generic; namespace Extension { static class AddOn { public static int Added(this ICollection coll, int x) { return coll.Count + x; } public static SCG.IEnumerable Where(this ICollection coll, Expression> pred) { Console.WriteLine("hallo"); // Func p = pred.Compile(); Delegate p = pred.Compile(); foreach (T item in coll) // if (p(item)) if ((bool)p.DynamicInvoke(item)) yield return item; } static void Main(String[] args) { HashSet hs = new HashSet(); hs.Add(new Person("Ole")); hs.Add(new Person("Hans")); foreach (Person q in (from p in hs where p.name.Length == 4 select p)) Console.WriteLine(q); } } class Person { public readonly String name; public Person(String name) { this.name = name; } public override String ToString() { return name; } } }