Reflection MemberInfo to Func<T1, T2>

 ̄綄美尐妖づ 提交于 2019-12-05 08:43:43
Func<int,bool> f = Delegate.CreateDelegate(
           typeof(Func<int,bool>), target, (MethodInfo)mi);

Note here that target is the object you want to use, since func is a non-static method. If it was a static method, you can omit that (or pass null). Alternatively, you can omit target (or pass null) if you make it a Func<Foo, int, bool> where Foo is the type that declares func.

However!!! Note that having a Func<int,bool> is largely meaningless in terms of creating a lambda expression; lambda expressions rarely use delegates.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!