Why does AutoMapper have an IValueFormatter when it has a seemingly much more powerful ValueResolver?

automapper, c#, mapping

Solution

The big difference is that formatters can be applied at the member, profile, type and global level. So you can do something like "ForSourceType.AddFormatter() in a profile, and now blammo! All your decimals now show up as money. Resolvers are strictly for custom member mapping.

Problem

It looks like an `IValueFormatter` takes a value of type `object` and returns a value of type `string`, while a `ValueResolver<TSource, TDestination>` takes a value of any type and returns a value of any type. So, it's more flexible. There is also the matter that, with a `ValueResolver`, you never need to cast the source to a particular type--you define it explicitly in your class definition. Given this, why use `IValueFormatter`? Does it do anything that can't be done with `ValueResolver`? Am I misunderstanding how it works?

Original source