繁体   English   中英

T4模板获取属性

[英]T4 Template Get Attributes

我正在尝试自定义MVCScaffolding中使用的T4模板。 NotMapped具有NotMapped属性的属性。

我的问题是属性集合似乎是空的。 我尝试打印出如下属性:

List<ModelProperty> properties = GetModelProperties(Model.ViewDataType, true);
foreach (ModelProperty property in properties) {
    if (!property.IsPrimaryKey && !property.IsForeignKey) {
#>
        <th>
            @Html.LabelFor(x => x.First().<#= property.Name #>)
            <!--
            <#foreach(var attribute in property.Type.CodeType.Attributes)
            {#>
              Attribute: <#=attribute.GetType().Name#>
            <#}#>
            -->
        </th>
<#
    }
}
#>

我找不到任何有关它的实际工作的信息,到目前为止,这是一个非常缓慢的反复试验。 获取属性或让模板忽略未映射的属性的正确方法是什么?

这不是您的问题的确切答案,但它将提供有关该问题的更多信息。 我的经历完全一样。 关于这个问题有一些奇怪的事情:

  • 以前工作过。 我在2个月前运行相同的代码(它来自源代码控制,所以我确定),今天它失败了。
  • 从T4引擎(例如MVC应用程序)外部运行时相同的代码完全正常。

我已经改变了我的代码,因此它可以从Visual Studio外部运行:

string assemblyPath = Host.ResolveAssemblyReference("$(ProjectDir)$(OutDir)T4Mvc.dll");

改为:

string assemblyPath = @"D:\AbsolutePath\bin\T4Mvc.dll";

然后我使用TextTransform.exe而不是RMB> Run Custom Tool

采用

TextTransform.exe AjaxServices.tt -out AjaxServices.js

(您可以在以下位置找到TextTransform.exe:“C:\\ Program Files(x86)\\ Common Files \\ microsoft shared \\ TextTemplating \\ 10.0”)。

此外,我已禁用hosts特定标志。

从TextTransform.exe而不是VS执行时相同的模板工作得很好。 看来这是VS的某种问题。 请尝试使用TextTransform。 exe并告诉它是否有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM