Is it possible to define a new class within a t4 template?
I tried this but it gave me an error 'A template containing a class feature must end with a class feature'
<#+
public class AppSettingDefinition
{
private string _dataType;
public string DataType
{
get { return _dataType; }
set { _dataType = value; }
}
}
#>
We use this template to generate the code when we add a view or controller in MVC. The file extension of this template is tt. Basically when we add a view or controller using a scaffhold template it is called a T4 template. By using this template if we add a controller or view then it generates some code automatically.
t4 is basically a tool built into VS for doing text transformation, typically for doing code generation. Transform All T4 Templates searches your solution for *. tt files and executes them to create other text, again typically source code, files.
Yes this is possible, the error I received was because I had text after class feature closing tag #>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With