0

I have class A and class B:

class A
{
    public List<TypeEnum> Types { get; set; }
    ...

}

class B
{
    public List<string> TypesString { get; set; }
    ...
}

I am trying to map List to List:

CreateMap<ClassA, CLassB>() .ForMemebr(destination => destination.TypesString, m => m.ConvertUsing(source => ((byte)source.Types).ToString()))

Outcome: Desired outcome should be successful mapping from List of enums to List of strings for example: List<string> => ["1","2","3","5"]

How can I do that?

1 Answer 1

3

Try the following mapping configuration:

CreateMap<ClassA, CLassB>().ForMember(destination => destination.TypesString, 
                                      opt => opt.MapFrom(s => s.Types.Select(x => ((byte)x))));
Sign up to request clarification or add additional context in comments.

1 Comment

You can remove both ToString and ToList. AM does that for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.