T4标记语法含义?

Rod*_*eis -3 asp.net t4 c#-4.0

在ASP.NET(*.aspx*.tt)什么是下列标记的含义是:<#= #> <# #> <#+ #>

小智 6

您在问题中描述的标记与ASP.NET无关.它们是T4模板标记语法的示例.T4模板在Visual Studio中进行转换,可用于创建任何类型的文件,但最常见的是它们用于代码生成.

<#= #>执行标记中的代码并返回文本结果.例:

// in this example, TargetNamespace is set to "MuhNamespace"
namespace <#= this.TargetNamespace #> { // outputs: namespace MuhNamespace
Run Code Online (Sandbox Code Playgroud)

<# #>执行代码但返回void.例:

This collection contains the following foos:
<#foreach(var foo in bar){ #>
    <#= foo.Name + Environment.NewLine #>
<# } #>
Run Code Online (Sandbox Code Playgroud)

<#+ #>定义可在模板中调用的可重用方法.例如,

This collection contains the following types:
<#foreach(var foo in bar){ #>
    <#= GetType(foo) #>
<# } #>

<#+  public string GetType(foo){ return foo.GetType().FullName; } #>
Run Code Online (Sandbox Code Playgroud)

还有更多这些,其中的例子可以在这里找到.