【发布时间】:2019-11-27 19:58:20
【问题描述】:
我有这些课程:
public class BaseGrid
{
public int current { get; set; }
public int rowCount { get; set; }
public int total { get; set; }
public List<T> rows { get; set; }
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
回到我的控制器,我想做一些类似的事情:
List<Product> listOfProducts = new List<Product>();
BaseGrid baseGrid = new BaseGrid();
baseGrid.rowCount = 10;
baseGrid.total = 20;
baseGrid.current = 1;
baseGrid.rows = listOfProducts;
如何将“行”属性变成一个通用列表,例如在 runtime 中将 baseGrid.rows 转换为我想要的任何列表类型?
谢谢。
【问题讨论】:
-
提示:
BaseGrid需要是通用的。 -
@Amy:泛型是一个编译时概念,即使您指定具体类型也是如此。
-
@RobertHarvey 我知道。我认为你和我对这个问题的解释非常不同。
标签: c# list generics reflection