how to map one property of a class to another property of another class based on a condition.

12 views
Skip to first unread message

srfs...@gmail.com

unread,
Jan 16, 2017, 9:59:22 PM1/16/17
to AutoMapper-users

I am trying to figure out how to map one property of a class to another property of another class based on a condition.

For example I would like to map property stop of class A to property go of class B given that the stop property in not null.

What would one code the  ForMember method to accomplish this?


ex:
class A
{
  public DateTime? Stop {get;set;}
}

class B
{
  public DateTime? Go {get;set;}
}

  Mapper.Initialize(cfg =>
       cfg.CreateMap<A, B>()
         .ForMember(???????????????????)

         ));

Feel free to email me directly at srf...@mail.com for suggestions

Jimmy Bogard

unread,
Jan 17, 2017, 3:55:42 AM1/17/17
to automapper-users
There's a Condition method.

--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages