您好我在T4模板上遇到了一些问题。这是我的代码:
private void ResolveComplexType(PropertyInfo propertyInfo)
{
var property = propertyInfo.PropertyType;
if (property.IsGenericType && property.GetGenericTypeDefinition() == typeof(List<>))
{
var argumentType = propertyInfo.PropertyType.GetGenericArguments()[0];
PrintPropertiesInfo(argumentType);
}
else
{
PrintPropertiesInfo(property);
}
}
我在typeof(List<>))
上收到了Identifier_Literal期望错误。我在C#类上测试了完全相同的方法并且它运行良好。
有谁知道问题是什么?
修改
这是错误:
错误2 Identifier_Literal expected
答案 0 :(得分:2)
使用此示例代码,我在T4生成和编译中没有错误。尝试与您的代码进行比较。
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" language="C#v3.5" debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.dll" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#
// insert your template code here the tempalte code will be syntaxhighlighted
// and you will have intellisense for all namespaces in the full edition
string Greeting = "Hello";
#>
// This is the output code from your template
// you only get syntax-highlighting here - not intellisense
namespace MyNameSpace{
using System.Collections.Generic;
class MyGeneratedClass{
static void main (string[] args){
if(typeof(List<>).ToString() == "yadayadayada" ){System.Console.WriteLine("isYadayadayada");}
System.Console.WriteLine("<#= typeof(List<>) #>");
}
}
}
<#+
// Insert any template procedures here
void foo(){
System.Console.WriteLine(typeof(List<>));
}
#>