【问题标题】:passing value from asp.net page to t4 template将值从 asp.net 页面传递到 t4 模板
【发布时间】:2013-05-31 05:50:28
【问题描述】:

我希望将我的 asp.net 网页中的字符串值传递给 t4 运行时模板。运行时模板包含更多模板文件。即。

我的运行时模板是 runTym.tt

这个 runTym.tt 包含两个 t4 模板,即:t1.ttt2.tt

runTym.tt 代码是这样的:

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ include file="t1.tt" #> 
<#@ include file="t2.tt" #>

我想将一个值传递给 t1.tt 文件。但是,我正在从 asp.net 网页访问 runTym.tt 文件。

runTym runT = new runTym();
string val= runT.TransformText();

有没有办法通过runTym.tt将参数值传递给t1.tt

【问题讨论】:

    标签: c# asp.net t4


    【解决方案1】:

    查看运行时模板正在生成的类,并在您自己的文件中添加该类的第二部分。在该部分中添加一个公共属性,然后在 newing 运行时模板之后和调用 TransformText() 之前设置该属性。

    如果您希望将所有内容都保存在一个文件中,则将属性添加到模板末尾的类功能块中,使用&lt;#+ #&gt; 作为分隔符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 2017-02-21
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多