Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a new class within a t4 template?

Tags:

t4

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; }
        }
    }
#>
like image 343
atreeon Avatar asked Feb 05 '14 11:02

atreeon


People also ask

What is the purpose of using T4 templates?

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.

What is transform all T4 templates?

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.


1 Answers

Yes this is possible, the error I received was because I had text after class feature closing tag #>

like image 177
atreeon Avatar answered Sep 27 '22 22:09

atreeon