动态程序集和方法
我已经编写 .NET 和 C# 多年了,但最近才在反射上下文中遇到 DynamicMethod
类型以及动态程序集的概念。它们似乎总是在 IL(运行时代码)生成中使用。
不幸的是,MSDN 在定义动态程序集/方法实际是什么以及它们应该用于什么方面做得非常糟糕。有人可以在这里启发我吗?和 DLR 有什么关系吗?它们与运行时静态(正常)生成程序集和方法有何不同?关于如何以及何时使用它们,我应该了解哪些信息?
I've programmed .NET and C# for years now, but have only recently encountered the DynamicMethod
type along with the concept of a Dynamic Assembly within the context of reflection. They seem to always be used within IL (runtime code) generation.
Unfortunately MSDN does an extraordinarily poor job of defining what a dynamic assembly/method actuallty is and also what they should be used for. Could anyoen enlighten me here please? Are there anything to do with the DLR? How are they different to static (normal) generation of assemblies and methods at runtime? What should I know about how and when to use them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DynamicMethod 用于创建方法而无需任何新程序集。它们也可以为类创建,这样您就可以访问它的私有成员。最后,DynamicMethod 类将构建一个可用于执行该方法的委托。例如,为了访问私有字段:
希望有帮助。
DynamicMethod are used to create methods without any new assembly. They also can be created for a class, so you can access it's private members. Finally, the DynamicMethod class will build a delegate you can use to execute the method. For example, in order to access a private field:
Hope it helps.