user8090896
user8090896

Reputation:

How to use Mapper.Map with function?

I know how to use map without function. This is input:

Id: 1
Name: Something
Color: -9690922

And expected output:

Id: 1
Name: Something
Color: (29, 3, 201, 1)

I have a function that converts this color from number, but how to use it within the mapper?

Upvotes: 0

Views: 1185

Answers (1)

shbht_twr
shbht_twr

Reputation: 550

You should use MapFrom option while creating map. So if your function to convert colour from number is CreateCol() use something like:

 Mapper.CreateMap<EFAddress, Address>()
  .ForMember(dest => dest.Color, opt => opt.MapFrom(src => 
  CreateCol(src.Color)));

Upvotes: 2

Related Questions