什么是IL编织?
我刚刚看到 Ayende 的帖子今天关于 PostSharp。 我下载了代码并尝试了一下,我认为这是我见过的处理 AOP 的最酷、最容易使用的方法。
Ayende 在他的帖子中表示,PostSharp 通过 IL Weaving 实现了它的魔力。 现在,在某种抽象层面上,我可以推断出这意味着什么,但我想看看是否有更详细的答案。 不幸的是,很长一段时间以来,谷歌第一次对我来说一无所获。 所以我认为这对 StackOverflow 来说是一个很好的问题(因为我已经订阅 Jeff 的博客好几年了,并且知道这个网站正在做它的事情)。
那么 IL Weaving 到底是什么以及它是如何实现的呢?
I just saw Ayende's post today about PostSharp. I downloaded the code and tried it out, and I thought it was the coolest, most easy to use way to handle AOP that I've seen.
In his post, Ayende says that PostSharp accomplishes it's magic via IL Weaving. Now, at some abstract level I can deduce what that means, but I wanted to see if there was a more detailed answer out there. Unfortunately, for the first time in a very long time, Google came up empty for me. And so I thought this would be a great question for StackOverflow (since I've been a subscribe to Jeff's blog for a couple years now and knew this site was doing its thing).
So what exactly is IL Weaving and how is it accomplished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编织是指将功能注入现有程序的过程。 从概念上讲,这可以在多个级别上完成:
理论上你可以更深入地使用编译为本机指令的可执行文件进行编织,但这会增加很多复杂性,而且我不知道有什么可以做到这一点。
Weaving refers to the process of injecting functionality into an existing program. This can be done conceptually at a number of levels:
In theory you could go one deeper and weave with an executable compiled to native instructions, but this would add a lot of complexity and I'm not aware of anything that does this.
IL Weaving 与 ByteCode Weaving 类似。 .Net 编译为由 .NET clr 运行的中间语言。 IL Weaving 基本上是分析和改变中间语言。 由于它是在该级别完成的,因此可以对所有 .NET 语言完成。
IL Weaving is simlar to ByteCode Weaving. .Net compiles to an intermediate language which is run by the .NET clr. IL Weaving is basically analyzing and altering the intermediate language. Since it is done at that level it can be done for all .NET languages.
如果您改为 Google MSIL 注入,可能会有所帮助。 此链接来自 PostSharp 它解释得很好。
我的公司最近购买了一款名为dynaTrace的产品,用于性能诊断。 它使用 MSIL 注入来检测方法。 基本上,它在方法之前和方法计时之后添加 IL 代码(我确信还有更多内容)。
以及此处 是对这个过程相当复杂但很好的解释。
Might help if you Google MSIL Injection instead. This link is from PostSharp and it explains it well.
My company has recently bought a product called dynaTrace for performance diagnosis. It uses MSIL injection to instrument around methods. Basically it adds IL code before your method and after to time the method (I am sure there is a lot more to it than that).
And here is a fairly involved but good explanation of the process.