在为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);
}
然而,
在引入泛型时,meth.ReturnType.Name
是一个泛型集合,生成奇怪的字符,生成的代码就会中断。
我首先在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);
记住‘1(撇号和1)在返回类型名称之后,在底线上低于符号之前。这发生在所有包含泛型返回类型的生成代码中。
,内省者在这里发现了一些错误,还是编码问题?
发布于 2011-04-13 08:28:44
这不是编码问题,PagedList'1<Portal.BLL.BO.Employee>
(泛型类型类似于'1
)意味着这是带有一个类型参数的泛型类型。您需要手动构造此返回类型以使其正常工作。
https://stackoverflow.com/questions/5645950
复制相似问题