DCSIMG
Creating AOP IL Emitting framework – Part 2 - IHateSpaghetti {code}

IHateSpaghetti {code}

VSX, DSL and Beyond by Eyal Lantzman

Syndication

Coding / Architecture

Extensibility /DSL

Projects

Articles

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:

Variables

Helper class overview:

Helper 

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.

Generation Context

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:

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

Published Wednesday, August 13, 2008 8:18 AM by Eyal

Comments

# Creating AOP IL Emitting framework – Part 3@ Saturday, August 16, 2008 12:03 PM

In the previous post I talked about how to create a simple, not really helpful (yet), proxy class. In

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: