[英]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>
<#
}
}
#>
我找不到任何有關它的實際工作的信息,到目前為止,這是一個非常緩慢的反復試驗。 獲取屬性或讓模板忽略未映射的屬性的正確方法是什么?
這不是您的問題的確切答案,但它將提供有關該問題的更多信息。 我的經歷完全一樣。 關於這個問題有一些奇怪的事情:
我已經改變了我的代碼,因此它可以從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.