给定是具有索引属性的类
public class Foo
{
public int Bar1 { get; set; } = 17;
public int Bar2 { get; set; } = 42;
public int Bar3 { get; set; } = 99;
...
Bar<n>
}
结果是
int列表包含17,42,99 ...
如何配置这样可以使用Automapper的映射器
List<int> bars = mapper.Map<List<int>>(foo);
您可以通过Reflection来实现
List<int> bars = new List<int>(foo.GetType()
.GetProperties()
.Where(x => x.PropertyType == typeof(int))
.Select(x => (int)x.GetValue(foo)));