Hello,
I am trying to create an overloaded Add method as an extension to the OrderedDictionary class and would like to add the key/value based on some curried predicate.
The calling code would look like this:
OrderedDictionary dict = new OrderedDictionary();
Predicate<int> lessThan5 = i=>; i < 5;
Predicate<string> lenOf2 = s=> s.length == 2;
dict.Add("01","Name", lessThan5 );
dict.Add("02","place", lenOf2);
I have created an extension method like so:
public static class CollectionExtensions
{
public static void Add(this OrderedDictionary s, string k, string v, Predicate p)
{
if (p)
{
d.Add(k, v);
}
}
}
But it doesn't work because I get a compiler error reading "cannot convert Predicate to bool".
Does anyone know what I am missing?
Thanks for any help. -Keith