I’m wondering if anyone out there knows of any T4 template based method interception systems?
We are beginning to write mobile applications (currently with MonoTouch for IOS). We have a very nice core set of DI/IoC functionality and I’d like to leverage this in development for the new platform. Since runtime code generation Reflection.Emit is not supported, I’m hoping to use T4 templates to implement the dynamic interception functionality (+ TinyIoC as a container for resolution).
We are currently using Castle Windsor (and intend to continue doing so for our SL and full .NET development), but all of the Windsor specific ties are completely encapsulated, so given a suitable T4 solution, it shouldn’t be hard to implement an adapter that uses a T4 based implementation instead of Windsor.
If I understand correctly you want to use T4 to generate code on the fly (at runtime). I’m not aware of any system that does this, but I don’t think it would be very hard to write such a thing.
What you need to do is instruct the C# (or any other .NET compiler) to compile some code and generate an assembly. When this is done, you need to load this assembly into your AppDomain. After that you can use the types in that dynamically loaded assembly.
The T4 template engine is (if I’m not mistaken) part of Visual Studio so the hard part will be to instruct the template engine to generate the code, possibly without your application to need a dependency on Visual Studio or to even start it (that would be awful).
If you don’t need the full capabilities of T4 (which is likely) you could also spit out some .NET code yourself, safe it to a file and instruct the C# compiler to generate an assembly for you.
Good luck.