Creating AOP IL Emitting framework – Part 2
I managed to write some code from the last post in this series and I got a name for the project - InterceptIt and I uploaded the initial drop.
I created IL emitter helper class that will be in charge of declaration of variables, constants, members, methods, constructors, properties and method and constructor invocation.
Variables:

Helper class overview:
When creating a constructor or method the returned parameter is IGenerationContext that provides access to the ILGenerator for that context.
IGenerationContext and the concrete GenerationContextInternal class.

When I needed to see how the code is translated to IL I used ildasm.
For example:
1: //instance to the original type(aspect)
2: private TestClassDefaultConstructor m_instance = new TestClassDefaultConstructor();
3:
4: public string Method1(int num1, string text1)
5: { 6: return this.m_instance.Method1(num1, text1);
7: }
Will translated to the following IL:

Remarks regarding the IL above:
* ldarg.s 0 - will load the "this" instance to the stack
* ldfld .... - will load the local field (member) to the stack
* ldarg.s 1 - will load the first method argument to the stack. Generally, ldarg.s i will load method argument i-1 to the stack (i>0)
* call - call the method (the parameters are automatically popped out of the stack based on the method signature
*stloc.s - store the current stack item to specific local variable
* ldloc.s - loads specific local variable to the stack
* ret - returns from the method (and returns the current item in the stack as the output result).
For the full implementation fell free to download it from CodePlex - IterceptIt.
In the next post on AOP I'll show you how you can add a bit more complexity to the generated code so far.
That's it for this time you can download the relevant change set (35709) or browse the code in this project's codeplex site .
STAY TUNED