I have a dictionary that I want to filter in different conditions, for example.
IDictionary<string, string> result = collection.Where(r => r.Value == null).ToDictionary(r => r.Key, r => r.Value);
I would like to pass the Where clause as a parameter to a method that does the actual filtering, for example
private static IDictionary<T1, T2> Filter<T1, T2>(Func<IDictionary<T1, T2>, IDictionary<T1, T2>> exp, IDictionary<T1, T2> col) { return col.Where(exp).ToDictionary<T1, T2>(r => r.Key, r => r.Value); }
This is not compiled.
I tried calling this method using
Func<IDictionary<string, string>, IDictionary<string, string>> expression = r => r.Value == null; var result = Filter<string, string>(expression, collection);
What am I doing wrong?
source share