A lot of a particular C# WinForms app I've seen is code doing simple map开发者_StackOverflow中文版s between data and forms and back again. Surely, there has to be a better way. What's the best tool to do this type of mapping?
Goals:
- Industrial strength, reliable, tested, wide user base
- Preferably open source
- Convention based, minimal code for simple maps
- Configurable for more complicated maps
- Gets out of the way for cases that I want to do completely by hand
- Simple learning curve for the simple cases (i.e. 80% of usage)
Not that I necessarily am expecting something which meets all of those.
Extra points if you tell me about your experience, likes and dislikes of any tool you recommend.
Take a look at AutoMapper.
AutoMapper uses a fluent configuration API to define an object-object mapping strategy. AutoMapper uses a convention-based matching algorithm to match up source to destination values. Currently, AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer.
Personally I use AutoMapper to map back and forth between my domain models (used by the service tier) and my view models (used by the UI tier). It's a tool that I have been using in large scale production application without ever having any issues.
精彩评论