tags:

views:

20

answers:

1

I am trying to decide if I want to pursue Automapper as a technology to use at my company. Before I dig in, I have a question that I want to be sure is doable with automapper.

Say I have a property in my destination class that I don't want to fill with automapper. Is there a way to tell automapper to ignore the property and not fail when I call Mapper.AssertConfigurationIsValid()?

So, for example:

class DTOMyObject
{
     public int Test {get; set;}
     public int Test2 {get; set;}
     public int Test3 {get; set;}
     public int Test4 {get; set;}
     public int Test5 {get; set;}
}

class ViewMyObject
{
     public int Test {get; set;}
     public int Test2 {get; set;}
     public int Test3 {get; set;}
     public int Test4 {get; set;}
     public int Test5 {get; set;}

     public int MyCustomUnMappedProperty{get; set;}
}

After mapping these (with ViewMyObject as the destination), I want to be able to call Mapper.AssertConfigurationIsValid() and have it not fail if (and only if) MyCustomUnMappedProperty is the only one one that is unmapped.

Is there a way to do that? If so, can you show me an example?

+2  A: 
Mapper.CreateMap<Src, Dest>()
    .ForMember(d => d.MyCustomUnmappedProperty, o => o.Ignore());
Patrick Steele