cezarypiatek / MappingGenerator

:arrows_counterclockwise: "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator
MIT License
1.03k stars 119 forks source link

Conditional mappings based on the Case/Specified flags #134

Open imtrobin opened 3 years ago

imtrobin commented 3 years ago

Hi, I'm using newtonjson with a rather obscure feature for Updating

public class UpdateDTO
{
   public string? TestString = null;
   public bool    TestStringSpecified; // true if specified in json
}

Ideally,the mapping generated would be like this

static void Update (UpdateDTO u, Target target)
{
   if (u.TestStringSpecified)      target.TestString = u.TestString;
}

I'm wondering if mapping generator can generate this kind of mapping code, or is there a better way?

cezarypiatek commented 3 years ago

Hi,

It looks like a custom mapping logic but I came across on a similar approach while working with protobuf. I think it's wort to implement it but I can't promise any date, right now I'm busy with #133