views:

211

answers:

1

I am talking about those Code Contracts that will end up in .NET 4.0. What binary rewriter do they use to inject the code that makes it all work and is it publicly available? I hope it's not just a compiler thing because I would love to be able to use their binary rewriter for AOP.

+2  A: 

If you want to write your own AOP, or anything else that modifies IL you may want to look at MS Research's Common Compiler Infrastructure project on Codeplex . It is an open source bag of really great tools that provides both an IL reader and IL writer implementation.

Jason Bock also has a series of blog posts on Code Injection With CCI that give a good overview of implementing an AOP style assembly modification with the tools.

Joe Kuemerle
Great response. Thank you very much for pointing that out. I'll look into it. The reason for my question was actually that I was looking for a binary rewriter that was well documented and supported, and I assumed Microsoft would be a good provider of that.
Hermann
http://blog.dotnetwiki.org/2009/04/16/ReadMorphTweakWriteMSILWithCCIOpenSource.aspx even says that CCI is used by FxCop, ILMerge, Spec# or Code Contracts.
Hermann
The Code Contracts binary rewritter is built on top CCI that is available on CodePlex. The APIs to mine the Contracts are already published in the cciast.codeplex.com project (look for IContractProvider).
Peli