InfoQ Homepage News AutoMapper 3 Adds Open Generic and Callback Support

AutoMapper 3 Adds Open Generic and Callback Support

This item in chinese


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


Educational Content

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.

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

Community comments

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

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


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.