Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

.net - What is 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...