This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24091|Reply: 0

[Source] AutoMapper Conversion Tutorial Between Objects [Source Code]

[Copy link]
Posted on 6/14/2017 4:09:44 PM | | | |


What is AutoMapper?

AutoMapper is an object-to-object mapper. Object-to-object mapping works by transforming one type of input object into a different type of output object. What makes AutoMapper interesting is that it provides some interesting conventions for the boring thing of mapping type A to type B. As long as type B adheres to the conventions already established by AutoMapper, in most cases, mapping two types of zero configurations will do.

Why use AutoMapper?

Mapping code is boring. Testing the mapping code is more boring. AutoMapper offers some simple configuration, as well as some simple mapping tests. The real question may be "why use object-to-object mapping"? Mapping can happen in many places in an application, but most often it happens at the boundaries between layers, such as between UI/Domain layers, or between Service/Domain layers. Focusing on one layer often conflicts with focusing on another, so object-to-object mapping isolates the model so that only the type of concern for each layer is affected.


An example I wrote myself that includes:

1: Conversion of int and string
2: Conversion of int and int
3: Conversion of enums and strings
4: Conversion of objects and strings
Wait a minute

Source Object:



Target audience:



The conversion code is as follows:



Source code download:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:AutoMapper type conversion error solution
Next:IIS 7 Application Pool Automatic Recycling Solution for Shutdown
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com