Patrick Karcher
Patrick Karcher

Reputation: 23603

Is there any way to have functions in basic T4 templates?

By basic T4 template, I mean not using T4 Toolkit or any of the add-ins.

My T4 is getting a little complicated, but I'd like to keep in self-contained for now. Is there a way have functions in your T4 template, without referencing external assemblies?

Upvotes: 40

Views: 12848

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300549

You mean like this:

<#+
    public List<string> Dostuff()
    {
        List<string> result = new List<string>(); 

        // ...

        return result;
    }
#>

Here's a complete example: Reading a Xml File in T4 Templates

Oleg Sych's T4Toolbox is a good resource.

Upvotes: 65

Related Questions