代码生成和T4文本模板中的字符错误
||
在为WCF服务生成控制器,合同和实现时,我使用
Microsoft FxCop 1.35\\FxCopSdk.dll
Microsoft FxCop 1.35\\Microsoft.Cci.dll
获取有关基础业务对象类的信息。
相关的代码段生成这样的控制器,例如:
来自webservice.tt的摘录:
public <#=meth.ReturnType.Name#> <#=meth.Name #> (<#=parametersIn#>) {
return <#=meth.DeclaringType.Name#>.<#=meth.Name#>(<#=parametersOut#>);
}
通常会产生类似
public Employee GetEmployee (Int64 id) {
return EmployeeController.GetEmployee(id);
}
然而
当引入泛型时,“ 3”是泛型集合,将生成奇怪的字符,并且所生成的代码将被破坏。
例如,我首先在BLL组件中生成一个控制器,例如:
public static PagedList<<#=t.Name#>>
GetAll<#=t.Name#>s(string sortby, int pageindex, int pagesize) {
return <#=t.Name#>.GetPaged(sortby, pageindex, pagesize);
}
结果是:
public static PagedList<Employee>
GetAllEmployees(string sortby, int pageindex, int pagesize) {
return Employee.GetPaged(sortby, pageindex, pagesize);
}
看来进展顺利,程序集得以建立。
但是,当我在该程序集上使用自省功能时,
WCF组件,例如生成服务合同,例如:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = \"<#=meth.Name#><#=parametersTemplate#>\")]
<#=meth.ReturnType.Name#> <#=meth.Name#> (<#=parametersIn#>);
它生成错误的代码:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = \"GetAllEmployees?sortby={sortby}&pageindex={pageindex}&pagesize={pagesize}\")]
PagedList`1<Portal.BLL.BO.Employee> GetAllEmployees (String sortby, Int32 pageindex, Int32 pagesize);
请注意在returntypename之后,底行中的低于符号之前的`1(撇号和1)。所有包含通用返回类型的生成代码都会发生这种情况。
内省员会在这里发现错误还是编码问题?
没有找到相关结果
已邀请:
1 个回复
才改隘瘁
-泛型类型看起来像
-表示这是具有一个类型参数的泛型类型。您需要手动构造此返回类型才能使其正常工作