我可以从 MethodDefinition (Cecil) 获取 MethodInfo 吗? [英] Can I get MethodInfo from MethodDefinition (Cecil)?

查看:118
本文介绍了我可以从 MethodDefinition (Cecil) 获取 MethodInfo 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 MethodInfo,有没有办法将 Cecil 的 MethodDefinition 转换为 MethodInfo?

I want to work with MethodInfo, is there a way to cast Cecil's MethodDefinition to MethodInfo?

推荐答案

不是 - 这两种结构虽然内容相似,但几乎没有任何关系.

No - the two structures, while similar in content, have almost nothing to do with each other.

引用 Google 上的此主题组:

To quote from this thread on Google Groups:

Cecil 不适用于 CLR 的反射 API;它有自己的内部模型,它自己加载所有程序集,绕过CLR的加载机制.

Cecil does not work with the CLR's Reflection APIs; it has its own internal model, and it loads all assemblies itself, bypassing the CLR's loading mechanism.

该线程提供了一些关于如何绕过这一事实的想法,但它也正确地指出,在大多数情况下,正确的答案是仅使用 CLR 的反射系统,如果这是您真正想要的.

That thread gives some ideas on how to get around this fact, but it also correctly states that in most cases the correct answer is to just use the CLR's Reflection system if that is what you really want.

这篇关于我可以从 MethodDefinition (Cecil) 获取 MethodInfo 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆