vs2013 安装 automapper
Install-Package AutoMapper -Version 2.1.267.0
automapper的使用
class Program
{
static void Main(string[] args)
{
Man man = new Man() { FirstName="liu",LastName="tian",age=10,Gender="男",weight=120,wan=true};
Country country = new Country();
AutoMapper.Mapper.CreateMap<Man, Person>().ConstructUsing(m=>new Person()
{
name =country.GetCountry(m.age)+ m.FirstName + m.LastName,
xingbie=m.Gender,
weight = m.weight.ToString(),
gay=m.wan?"gay":"nogay"
});
Person p = AutoMapper.Mapper.Map<Man, Person>(man);
Console.WriteLine(p.age);
Console.Read();
}
}
public class Country
{
public string GetCountry(int id)
{
return "中国";
}
}
public class Person
{
public int age;
public string name;
public string xingbie;
public string weight;
public string gay;
}
public class Man
{
public string FirstName;
public string LastName;
public int age;
public string Gender;
public int weight;
public bool wan; //是否是弯的
}
}
还没有评论,来说两句吧...