泛型 - 类型参数声明必须是标识符而不是类型

bur*_*1ce 2 c# generics

在第一行,我得到此编译错误."类型参数声明必须是标识符而不是类型." 有没有办法来解决这个问题?

 public class ExtJsGridJsonModel<IEnumerable<T>>
{
    [DataMember(Name = "total")]
    public int Total { get; set; }

    [DataMember(Name = "rows")]
    public IEnumerable<T> Rows { set; get; }

    public ExtJsGridJsonModel(IEnumerable<T> rows, int total)
    {
        this.Rows = rows;
        this.Total = total;
    }
}
Run Code Online (Sandbox Code Playgroud)

更新:

很抱歉我的问题和意图缺乏细节.基本上,我的最终目标是这样做:

new ExtJsGridJsonModel<Company>();
Run Code Online (Sandbox Code Playgroud)

而不是这个:

new ExtJsGridJsonModel<IEnumerable<Company>>();
Run Code Online (Sandbox Code Playgroud)

基本上,我想通过省略IEnumerable类型来减少代码.我该怎么做呢?

D S*_*ley 5

只需取出IEnumerable你的声明部分:

public class ExtJsGridJsonModel<T>
{
    [DataMember(Name = "total")]
    public int Total { get; set; }

    [DataMember(Name = "rows")]
    public IEnumerable<T> Rows { set; get; }

    public ExtJsGridJsonModel(IEnumerable<T> rows, int total)
    {
        this.Rows = rows;
        this.Total = total;
    }
}
Run Code Online (Sandbox Code Playgroud)