How to create a method that encapsulates the T4 template text section?

后端 未结 2 1648
悲哀的现实
悲哀的现实 2021-02-10 00:26

Instead of this .tt:

<#@ template debug=\"false\" hostspecific=\"true\" language=\"C#\" #>
<#@ import namespace=\"System.IO\" #>
<#@ output extens         


        
2条回答
  •  情歌与酒
    2021-02-10 00:40

    This is an alternative solution not using class feature blocks <#+ ... #>. Using a lambda expression inside usual statement blocks <# ... #> allows defining a local function as follows:

    <#@ template language="C#" #>
    <#@ output extension=".txt" #>
    
    <# Action output = () => { #>
    loooooooong text <#= "message" #>
    <# }; #>
    
    <# output(); #>
    

    This template produces the output below:

    loooooooong text message
    

提交回复
热议问题