2

Using mapster and have the following problem
https://github.com/MapsterMapper/Mapster

I have to class and a dto class.

public class Client {
    public string Requirements { get; set; }
}

public class ClientDto {
    public bool RequirePkce { get; set; }
}

And now i want to map the Value from Requirements to the boolean values in the ClientDto class, and back. From string to the boolean is easy, i'll use following:

config.NewConfig<Client, ClientDto>()
                .Map(dest => dest.RequirePkce, src => (src.Requirements ?? "").Contains("ft:pkce"));

But i can't find a Way to map back to the string field... Is there any way to have access to to destination object when mapping?` Like the following:

config.NewConfig<ClientDto, Client>().Map(dest => dest.Requirements, (src: ClientDto, dest: Client) => {
            var ls = dest.Requirements.Split(";").ToList();

            if (src.RequirePkce)
            {
                if (!ls.Contains("ft:pkce"))
                {
                    ls.Add("ft:pkce");
                }
            }
            else
            {
                if (ls.Contains("ft:pkce"))
                {
                    ls.Remove("ft:pkce");
                }
            }

            return String.Join(";", ls);
          });

And thats just one example! There are even more values in the Requirements string property which i have to map in a similar way. I hope I have explained my problem understandably...

0 Answers0