linq - How to filter a collection of delegates based on their parameter's generic type in C#? -
i have collection of delegates:
ilist<action<isomeinterface>> _delegates = new list<action<isomeinterface>>();
and method* add delegates it**:
public void adddelegate<t>(action<t> del) t : isomeinterface { _delegates.add(si => del((t)si)); }
now want filter delegates collection based on concrete type delegate constructed with:
var adelegates = _delegates.where(d => d action<someinterfaceimpla>); foreach(var del in adelegates) { .... }
which return delegates, not action<someinterfaceimpla>
delegates. question is, predicate should used in where
clause correct subset filtering? full code example available here.
* fluent api (generic) method using hence use of generic type here
** based on answer here
this not prettiest thing ever, works
var adelegates = someclass.delegates.where(d => d.method.declaringtype.generictypearguments.firstordefault().isassignablefrom(typeof(someinterfaceimpla)));
Comments
Post a Comment