I guess there are two ways to achieve this.
Your first option is to use the AOP structure to enter the toolkit code as a stage of subsequent compilation. This can be precisely targeted and allows you to do almost anything you want, but works best when you can isolate the desired additional behavior from the rest of the code. PostSharp is a leading competitor in this area, but I'm sure there are others.
The second option is to connect to the profiler API, which makes TypeMock Isolator and Microsoft in-house. This basically gives you the means to intercept everything, but it is quite software invasive and, of course, not a trivial task to implement. In fact, I would not recommend this approach to anyone except to mention it for completeness.
Morten mertner
source share