I want to use AutoMapper with proto3, but the biggest problem I have is in mapping from a source property that may allow null
into a proto that never does. When doing such population manually, one must do something like this:
var proto = new Proto();
if (source.Field != null)
{
proto.Field = source.Field;
}
I still find it absurd, but that's apparently how it is with proto3.
Anyway, this means that mappings must have conditions on them to ensure null
values do not propagate to the proto:
config
.CreateMap<Source, Proto>()
.ForMember(
x => x.Field,
options => options.Condition(source => source.Field != null));
I can feel this getting old really fast as I have a lot of properties in my protos.
What I'm wondering is whether there a way for me to handle this at a higher level of abstraction?