First, install
Our installation is installed and used in Nuget way vs
But one thing to note is that when you install version, I use the example of .net framework 4.5.2, so I installed AutoMapper version is 7.0, if the installation fails, it can reduce the release.
Second, placement
static void the Main ( String [] args) { // configuration, write arbitrary location, because it is the global Mapper.Initialize (m => m.CreateMap <the Person, People> ()); // the object the Person Person = new new the Person () { the Name = " text1 " , Age = 12 is , Birthday = the DateTime.Now, Sex = to true , the Salary = 1000 }; People PEO = new new People (); //Disable Bit Null // conversion Mapper.Map (Person, PEO); // display Console.WriteLine (peo.Name); Console.WriteLine (peo.Age); Console.WriteLine (peo.Birthday); Console.Read () ;
There is also a way that does not require New instantiated:
PEO = People new new People (); // Disable Bit Null
We can be converted directly, however, requires the use of generics to specify the type of conversion
People peo2 = Mapper.Map<People>(person);
Three,
//配置 Mapper.Initialize(m => { m.CreateMap<Person, People>(); m.CreateMap<ABP, People>(); });