I'm looking for a method to convert instance of MemberInfo
to "Func" type (to use it through lambda expression later).
Lets, say I have a member function of type
public bool func(int);
Using reflection, I somehow get instance of MemberInfo
"mi", now i want to convert it to Func<int, bool>;
type. something like:
Func<int, bool f = myType.GetMember(mi.Name);
Is there a way to do it?
ps. Marc Grawell's answer resolves my issue, no need for further comments
Note here that
target
is the object you want to use, sincefunc
is a non-static
method. If it was astatic
method, you can omit that (or passnull
). Alternatively, you can omittarget
(or passnull
) if you make it aFunc<Foo, int, bool>
whereFoo
is the type that declaresfunc
.However!!! Note that having a
Func<int,bool>
is largely meaningless in terms of creating a lambda expression; lambda expressions rarely use delegates.