MappingGenerator icon indicating copy to clipboard operation
MappingGenerator copied to clipboard

Conditional mappings based on the Case/Specified flags

Open imtrobin opened this issue 4 years ago • 1 comments

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?

imtrobin avatar Aug 04 '20 05:08 imtrobin

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

cezarypiatek avatar Aug 04 '20 20:08 cezarypiatek