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

2

9

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; }
        }
    }
#>
Biltong answered 5/2, 2014 at 11:11 Comment(0)
B
8

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

Biltong answered 5/2, 2014 at 11:50 Comment(0)
N
1

I will add an answer because the selected one wasn't enough for me. I had to move the class to a separate file named: SomeClass.ttinclude with the content like for example:

<#+
public class SomeClass
{
    ...
}
#>

And then include it in the .tt file:

<#@ include file="SomeClass.ttinclude" #>
Nakamura answered 21/6 at 10:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.