What is IL Weaving?

I just saw an Ayende post today about PostSharp. I downloaded the code and tried it out, and I thought it was the coolest, easiest to use AOP processing method I've seen.

In his post, Ayende says PostSharp does magic through IL Weaving . Now, at some abstract level, I can deduce what this means, but I wanted to see if there is a more detailed answer. Unfortunately, for the first time in a very long time, Google came up empty for me. And so I thought it would be a big question for StackOverflow (since I had been a Jeff blog subscriber for a couple of years and knew that this site was doing its job).

So what exactly is IL Weaving and how is it done?

+44
postsharp
09 Oct '08 at 21:57
source share
3 answers

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

  • Embossing the source code will introduce lines of source code before compiling the code.
  • IL pairing (for .NET) adds code as IL instructions in the assembly
  • Working with byte code (for Java) works on a class file, see these comments wrt AspectJ

In theory, you could go even deeper and intertwine with an executable compiled into your own instructions, but that would add a lot of complexity, and I don't know anything that does this.

+20
Oct 09 '08 at 22:04
source share

IL. Weaving is a simple use. ByteCode Weaving..Net is compiled into an intermediate language that is run by .NET clr. IL Weaving mainly analyzes and modifies the intermediate language. Since this is done at this level, this can be done for all .NET languages.

+7
09 Oct '08 at 10:00
source share

Maybe if you use Google MSIL Injection. This link is from PostSharp , and it explains it well.

My company recently bought a product called dynaTrace for performance diagnostics. It uses MSIL injection for toolkit around methods. It basically adds IL code before and after your method (I'm sure this is a lot more for him).

And here is a pretty attractive but good explanation of the process.

+4
Oct 09 '08 at 22:02
source share



All Articles