0
我想這在某種程度上接受class_name
屬性,並創建一個類,名稱會是class_name
如何用T4模板創建一個自定義的部分類?
理想的價值,我應該能夠執行內部包含public partial class MyClass
定義MyClass.cs
我的模板,模板,這將設置class_name
到MyClass
此模板
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
public partial class <#=class_name #>
{
}
產生一個錯誤:
Error 1 Compiling transformation: The name 'class_name' does not exist in the current context
如何將class_name
的定義加入其中?
你想從你的代碼中執行此模板(MyClass.cs)或Visual Studio在您的項目.TT文件? – Frank
我想執行它從視覺工作室 – user2136963
有一個類似的帖子[這裏](http://stackoverflow.com/questions/15946802/how-do-i-pass-a-string-parameter-to-a-t4 -template)已經是,這是你正在嘗試做什麼? – Frank