BT

AutoMapper 3 Adds Open Generic and Callback Support

| by Jonathan Allen Follow 576 Followers on Dec 29, 2014. Estimated reading time: 1 minute |

AutoMapper, .NET’s most popular object-to-object mapping library, has been updated with a large set of new features including support for open generics and callbacks. AutoMapper 3.3 is expected to the final version in the 3.x series.

Custom destination type constructors

This feature allows developers to pass in a lambda that represents a custom constructor call. Normally this isn’t necessary, as AutoMapper is capable of matching up source properties to the constructor’s parameters. According to the documentation, “only use this method if AutoMapper can't match up the destination constructor properly, or if you need extra customization during construction.”

Open Generics

Open generics are generic types such as List<T> where the type parameter T hasn’t been provided yet. In previous version versions of AutoMapper, you could only provide closed generics such as List<int> or List<string>. Now you can write code such as…

Mapper.CreateMap(typeof(List<>), typeof(ObservableCollection<>));

Before and after map actions

Callbacks can now be added for mapping operations. These callbacks occur just before or after an object is mapped. In the example offered by the documentation, they populate a name property on an object using HttpContext.Current.Identity.Name instead of a property on the source object.

Replacing Member Names

In addition to whole member names, you can now map individual characters such as the accented é to an unadorned e. This mapping would apply no matter where the character is found in the member name.

Other Features

Other features mentioned in the announcement and release notes include

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT