2

I have a Member named "Name" and I'm using AutoMapper to map between my ViewModel and my base Model. However, I also have a method named "GetName()" on a separate ViewModel which seems to be overriding my "Name" member's 'get' on the actual model.

I've since renamed the method to "GetFullName()" and this is no longer a problem.

This work-around works just fine, however, I would like to know what override in AutoMapper I can implement to let it know to not map function values like "GetName()" to a member's 'get'.

Justin Williams
  • 697
  • 3
  • 12
  • Sounds interesting. Can you show some code? – lbrahim May 01 '15 at 21:43
  • I think you need to implement an `INamingConvention` interface, see [this answer](http://stackoverflow.com/questions/9418317/automapper-how-to-leverage-a-custom-inamingconvention) – Christian May 01 '15 at 21:54

1 Answers1

0

You can override via:

Mapper.CreateMap<Foo, FooDto>()
    .ForMember(d => d.Name, opt => opt.MapFrom(src => src.Name));
Jimmy Bogard
  • 26,045
  • 5
  • 74
  • 69
  • Good call, the problem (and I should have stated this earlier) is I do not know where else in our code base this could occur. I'm afraid other members are being overwritten by methods and want to prevent that from happening. – Justin Williams May 04 '15 at 13:07
  • There's no way to prevent that, other than to not name your methods confusingly. I wouldn't name things like this WITHOUT AutoMapper. – Jimmy Bogard May 04 '15 at 14:51