Custom value converters are designed to override the display of a specific member when AutoMapper is about to map objects:
Mapper.CreateMap<PersonData, Person>() .ForMember(dest => dest.Dic, opt => opt.ResolveUsing<DictionaryResolver>());
However, when you use a custom type recognizer, this requires full control over the display: there is no way to customize the display of one particular element:
Mapper.CreateMap<TPersonData, Person>().ConvertUsing(PersonConverter );
However, given that you have full control over the type conversion, there is nothing to stop the reuse of the value converter, you just need to reference it specifically: however, you will have to add an open method that returns the protected ResolveCore method:
class DictionaryResolver : ValueResolver<int, Dictionary> { public Dictionary Resolve(int source) { return ResolveCore(source); } protected override Dictionary ResolveCore(int source) {
Then, when converting types, you call it to resolve this property:
var person = new Person { Name = personData.Name }; DictionaryResolver resolver = new DictionaryResolver(); person.Dic = resolver.Resolve(personData.IntValue);
stuartd
source share