AutoMapper – A convention-based object-object mapper
AutoMapper uses a fluent configuration API to define an object-object mapping strategy. It uses a convention-based matching algorithm to match up source to destination values. Currently, it 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.
Conventions
Since AutoMapper flattens, it will look for:
- Matching property names
- Nested property names (Product.Name maps to ProductName, by assuming a PascalCase naming convention)
- Methods starting with the word “Get”, so GetTotal() maps to Total
- Any existing type map already configured
Basically, if you removed all the “dots” and “Gets”, AutoMapper will match property names. Right now, AutoMapper does not fail on mismatched types, but for some other reasons.
Features rundown
AutoMapper supports:
- Mapping of simple types
- Mapping to arrays from any IEnumerable source
- Custom member resolution, for that 1% case you have to do some extra mapping work
- Polymorphic array mapping
- Custom formatting for mapping from any type to a string
- Global formatters
- Null substitutes for formatting (i.e. a missing Product formats to “n/a”)
- Profiles, for separating different sets of configurations (JSON vs. ViewModel vs. EditModel etc)
Other features include:
- Convention of no null destination objects, ever.
- No null destination array properties, ever.
- A fluent configuration, with both a method chaining syntax (through Mapper) and object scoping (through a Profile)
For more information, please go to http://automapper.codeplex.com/