hi,
in my application (.net MVC, c#) im using a fixed structure for public methods of one of my modules.
When im adding a new public method to this module i need to add the following code:
1) a code segment in an existing file, something like:
[...attribute...]
[...attribute...].public ... {Method-Name}(...)
{
...init code...
}
2) two code files defining two classes. The name of these classes is built using the method name ({Method-Name}) appended with some suffix, for example:
using System...;
namespace ...
{
public class {Method-Name}Model
{
public {Method-Name}Model()
{
}
...common code...
}
}
I need to generate this code once (for each new method) - after which i edit the files and add the specific details & logic.
Currently i just copy the code of existing methods and modify it.
I've tried doing the above using
T4 Text Templates, however i could not find how to:
- run manually T4 scripts?
- run T4 scripts with parameters?
- run several T4 scripts one-after another?
- run a T4 script within an existing code file to add a code fragment template inside that file?
For example the following T4 template to generate the class from above:
<#@ template language="C#" #>
<#@ parameter type="System.String" name="MethodName" #>
<#@ output extension=".cs" #>
using System ...
namespace ...
{
public class <#= MethodName #>Model : ...
{
public <#= MethodName #>Model()
{
}
...common code...
}
}