views:

53

answers:

0

I have been using Automapper to map from my entities to my ViewModels successfully. I was getting tired of having to mark my Add and Edit Models with the [Required] attribute so I decided to add a custom Metadata Provider that would take any property ending with "X" and make it required. Needless to say now the conventions in Automapper no longer work. Is there a way to make some kind of custom convention rule with Automapper it state if the property ends with "X" trim it and use the resulting string?

Here is what I have tried, but does not seem to work:

 Mapper.Initialize(cfg => 
            {
                cfg.AddProfile<ViewModelProfile>();
                cfg.AddProfile<AddModelProfile>();
                cfg.AddProfile<EditModelProfile>();
                cfg.RecognizePostfixes("X");
            });

Any help would be great, thanks!