【发布时间】:2015-09-04 14:29:31
【问题描述】:
所以我有一个Objects 的列表,例如:
var animals = new List<Animal>() //add Animals`
我知道我可以将这些从 This Question 转换为 strings,例如:
List<Animal> animals = new List<Animal>();
List<string> strings = animals.Select(a => (string)a).ToList();
但是我想根据我在运行时作为string 输入的属性从animals 列表中获取List<string>
例如:
private List<string> GetList(string property)
{
return animals.Select(x => filterByReflection(property)).ToList();
}
所以我可以打电话:
var names = GetList("Name");
var types = GetList("Type");
var ages = GetList("Age");
这可能吗?
【问题讨论】:
标签: c# list reflection