将 B(C(),D()) 转换为 (c,d)=>B(()=>c(),()=>d()) - 从 MethodInfos 生成委托包装器?
最终,我期待一种基于反射的方法来为方法 B(C(),D()) 创建委托包装器 - 类似于 (c,d)=>B(()=> c(),()=>d())
第一个问题 - 假设您有一个 Methodinfo,创建与该方法签名相对应的委托类型(通过反射)需要考虑哪些因素?
您是否有任何这样做的开源项目的代码块的参考? :P
更新: 这是为 methodinfo 创建委托的通用方法 从 MethodInfo 构建委托? - 我认为递归包装参数部分是我周末必须解决的问题。
Ultimately, I'm looking forward to a reflection based approach to create a delegate wrapper for a method B(C(),D()) - to some what like (c,d)=>B(()=>c(),()=>d())
First question - Given that you've a Methodinfo, what are the considerations to create a delegate type (via reflection) which corresponds to that method signature?
Do you have a reference to the code chunk of any open source projects that does this? :P
Update: Here is a generic way to create a delegate for a methodinfo Builds a Delegate from MethodInfo? - I think recursively wrapping the parameters part is something I've to work out over the weekend.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
Expression
构建动态方法。这是根据您的问题的示例。我以Console.Write(string s)
为例。Use
Expression
to build dynamic methods. Here is an example according to your question. I'm takingConsole.Write(string s)
as an example.我设法从方法的 MethodInfo 创建一个工作委托,如下所示:
方法和委托:
代码:
输出:
但不确定它有多有用......
I managed to create a working delegate from the MethodInfo of a method like this:
Method and delegate:
Code:
Output:
Not sure how useful it is, though...