什么是IL编织?

发布于 2024-07-06 06:53:21 字数 454 浏览 9 评论 0原文

我刚刚看到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一桥轻雨一伞开 2024-07-13 06:53:21

编织是指将功能注入现有程序的过程。 从概念上讲,这可以在多个级别上完成:

  • 源代码编织将在编译代码之前注入源代码行
  • IL 编织(对于 .NET)将代码添加为程序集中的 IL 指令
  • ByteCode 编织(对于 Java)适用于类文件,请参阅这些评论 AspectJ

理论上你可以更深入地使用编译为本机指令的可执行文件进行编织,但这会增加很多复杂性,而且我不知道有什么可以做到这一点。

Weaving refers to the process of injecting functionality into an existing program. This can be done conceptually at a number of levels:

  • Source code weaving would inject source code lines before the code is compiled
  • IL weaving (for .NET) adds the code as IL instructions in the assembly
  • ByteCode weaving (for Java) works on the class file, see these comments wrt AspectJ

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.

各自安好 2024-07-13 06:53:21

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.

┈┾☆殇 2024-07-13 06:53:21

如果您改为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文