How can I override the type converter being used by AutoMapper for a given property?
For example, if I have:
public class Foo
{
public string Name { get; set; }
}
public class Bar
{
public string Name { get; set; }
}
Now I simply want to map Foo.Name to Bar.Name but using a specified type converter. I see how I can do it using:
Mapper
.CreateMap<Foo,Bar>()
.ForMember( x => x.Name, opt => opt.ResolveUsing<FooNameResolver>() );
But this hard-codes the conversion to use the Name property on Foo. If I have the same type of conversion on other properties in this or other classes, I have to create a resolver class for each.
And I don't want to specify a converter for string -> string as this conversion is specific to this property or others like it.
I just want to override the type converter! I'm sure this must be possible but I'm blanking on it :-(
I'm after something like this:
Mapper
.CreateMap<Foo,Bar>()
.ForMember( x => x.Name, opt => opt.Using<MySpecialStringConverter>() );