How can I access IEnumerable<T> extension methods on my custom subclass of BindingList<T>?
- by Dan
I have a custom subclass of BindingList<T> that I want to execute a LINQ query over using the handy extension methods. For example:
public int GetSum(MyList<T> list)
{
return list.Sum(x => x.Value);
}
But the compiler complains that it can't resolve Sum because it doesn't recognize list as an IEnumerable<T>, which it obviously is, because this works:
public int GetSum(MyList<T> list)
{
return ((IEnumerable<T>)list).Sum(x => x.Value);
}
Anyone have a clever way I can avoid the ugly and unecessary cast?