2011-04-13 40 views
1

在生成控制器,合同及其履行情况的WCF服务,我用的是错误的字符代码生成和T4文本模板

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是一个泛型集合,会生成奇怪的字符并且生成的代码将被破坏。

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); 
    } 

,似乎顺利,装配建立

如我第一次像生成控制器到BLL大会。 但是当我在这个程序集上使用内省来生成 WCF程序集中的代码时,例如,产生像servicecontracts:

[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)的后returntypename,比之前在底行符号越低。所有生成的包含通用返回类型的代码都会发生这种情况。

introspector在这里挑错了什么,或者它是一个编码问题?

+2

这不是编码问题,'PagedList'1 ' - 它是什么泛型类型看起来像 ''1' - 意味着这是具有一种类型参数的泛型类型。你需要手动构建这个返回类型以获得它的工作 – Stecya 2011-04-13 08:13:18

+0

啊哈,感谢这个非常有用的信息?请介意把它作为答案吗? – 2011-04-13 08:26:31

回答

3

这不是编码问题,PagedList'1<Portal.BLL.BO.Employee> - 它是什么泛型看起来像'1 - 意味着这是一种类型参数的泛型。你需要手动构建这个返回类型以使其工作