I have a display code as follows
Mapper.CreateMap<CalculationQueryResult, CalculationViewModel>() .ForMember(poco => poco.NomineeFee, opt => opt.ResolveUsing<FormattedCurrencyInt>() .FromMember(m => m.NomineeFee)) .ForMember(poco => poco.TotalContributions, opt => opt.ResolveUsing<FormattedCurrencyInt>() .FromMember(m => m.TotalContributions)) .ForMember(poco => poco.EquityInjection, opt => opt.ResolveUsing<FormattedCurrencyInt>() .FromMember(m => m.EquityInjection)) // ... SNIP Lots more members mapped with Formatted Currency Resolver
As you can see, I map multiple members using the same resolver to convert an integer to a formatted currency string. I do this for the vast majority, but not for all members of my poco class.
All these members will be displayed using matching based matching if I don't need to repeat these types. Its a huge amount of code to write for a simple task.
Is there a way to override the default behavior to convert int to string for one card, and then execute custom .ForMembers where I want something else. For example:
Mapper.CreateMap<CalculationQueryResult, CalculationViewModel>() .SetDefault<int,string>(opt => opt.ResolveUsing<FormattedCurrencyInt>()) .ForMember(poco => poco.Count, x=>x.MapFrom(s => s.Count.ToString()));
c # automapper
Twisted
source share