Mapster
Mapster copied to clipboard
Tweaking null propagation easily
Is there an easy way to change how null propagation works?
- If we wanted to throw an exception when null reference encountered? There are lots of various
Ignoremethods, similarly I wish there wereRequiredmethods or maybe anThrowIfNullargument to be passed in - If null encountered, use a provided value (I know atm it uses default or null value)
Hello @brgrz
Do you want to prevent null leaking from Source to Destination?
From this case:
- If null encountered, use a provided value (I know atm it uses default or null value)
Maybe it will help you Mapping with condition
@brgrz If you go out something like this?
I think it can be done )
TypeAdapterConfig<Source,Destination>
.NewConfig()
.Map(x=>x.Value, y=>y.Value).IfNullDefault(42)
.Map(x=>x.SomeValue, y=>y.SomeValue).IfNullAction(x=> GetThrow(x))
If we wanted to throw an exception when null reference encountered? There are lots of various Ignore methods, similarly I wish there were Required methods or maybe an ThrowIfNull argument to be passed in
@brgrz Can you describe in more detail the conditions in which you want to use this:
- Should this only apply to reference types, or also to nullable ValueType?
- Should this work for types declared in Nullable Enable Context or only for other types?