MVC Web API Get 方法返回泛型类型

本文关键字:返回 泛型类型 方法 Get Web API MVC | 更新日期: 2023-09-27 18:37:28

我想知道是否可以使用 mvc web API 返回泛型类型。

eg can I retrun List<T> and NOT List<int> or is this too crazy?
// adding a little more context 
// Controller
IRepoClassInterface repo = new ReopClassWorker();
public List<T> Get<T>(string date, string chartName)
{
    switch(chartName)
    {
       case "myCoolChartBrah":
       return repo.Get<MyListType>(date);
       case "anotherChart":
       return repo.Get<AnotherListType>(date);
    }
 }

MVC Web API Get 方法返回泛型类型

ASP.NET MVC Web API设计用于此,特别是使用OData查询的IQueryable。试一试就知道了。