I have build an Addin for code generation (C#, VS 08) for our team.
The addin creates a new menu entry if i click on a file in the solution explorer. There i can choose a destination test project where the 2 files are generated to.
For the code generation process i need informations from the selected item in the solution explorer (like Interfaces, generic types of the class declaration).
My source class looks like
public class CustomerLogic : BaseBL<T1, T2, T3>, ICustomerBL
The generated container class
public class CustomerContainer : BaseBLDummyContainer<T1, T2, T3>
The generated dummy class looks like
public class CustomerBLDummy : BaseBLDummy<T1, T2, T3, CustomerContainer>, ICustomer
How i realized it?
I created two templates (container and dummy), put placeholder to the spaces so the two template files look like
Containertemplate
public class $Classname$ : BaseBLDummyContainer<$T1$, $T2$, $T3$>
Dummytemplate
public class $Classname$ : BaseBLDummy<$T1$, $T2$, $T3$, $TContainer$>$, TInterface$
To generate the templates i have writen some code to
- create the files
- add them to the destination project
- create methods if needed
You can see, a "lot" of work to do only to generate some code.
- Now i consider if the generation with T4 is a better solution for my situation?
- Does i have some benefits of the T4 mechanism ? (I've only see some T4 samples in combination with EF or database related generation)
- Should i be more flexible with T4?
Thanks a lot.