[英]Automapper Mapping List<T> to class containing T
I have a class: 我有一堂课:
public class Person
{
public string Name {get;set;}
public string Address {get; set;}
public string DOB {get; set;}
}
A list: 一个列表:
List<Person> personList = new List<Person>();
This List contains 4 Person objects with names "Person1", "Person2", "Person3" and "Person4" respectively and all other values for the properties. 该列表包含4个Person对象,分别具有名称“ Person1”,“ Person2”,“ Person3”和“ Person4”,以及该属性的所有其他值。
Now I have another class: 现在我有另一堂课:
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();
Now my question is: How do I map the personList to Citizen. 现在我的问题是:如何将personList映射到Citizen。 I want to load all the values from the list to the citizen object. 我想将所有值从列表加载到公民对象。 Please help. 请帮忙。
You classes should look like this 你的课应该看起来像这样
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.