[英]Automapper Mapping List<T> to class containing T
我有一堂课:
public class Person
{
public string Name {get;set;}
public string Address {get; set;}
public string DOB {get; set;}
}
一个列表:
List<Person> personList = new List<Person>();
该列表包含4个Person对象,分别具有名称“ Person1”,“ Person2”,“ Person3”和“ Person4”,以及该属性的所有其他值。
现在我有另一堂课:
public class Citizen
{
public Person Abc1 {get; set;}= new Person{Name="Person1"};
public Person Abc2 {get; set;}= new Person{Name="Person2"};
public Person Abc3 {get; set;}= new Person{Name="Person3"};
public Person Abc4 {get; set;}= new Person{Name="Person4"};
}
var citizen = new Citizen();
现在我的问题是:如何将personList映射到Citizen。 我想将所有值从列表加载到公民对象。 请帮忙。
你的课应该看起来像这样
public class Citizen
{
public static List<Person> personList = new List<Person>() {
new Person{Name="Person1"},
new Person{Name="Person2"},
new Person{Name="Person3"},
new Person{Name="Person4"}
};
}
public class Person
{
public string Name {get;set;}
public string Address {get; set;}
public string DOB {get; set;}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.