Skip to content

Tweaking null propagation easily #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brgrz opened this issue Dec 11, 2024 · 2 comments
Open

Tweaking null propagation easily #740

brgrz opened this issue Dec 11, 2024 · 2 comments

Comments

@brgrz
Copy link

brgrz commented Dec 11, 2024

Is there an easy way to change how null propagation works?

  1. 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
  2. If null encountered, use a provided value (I know atm it uses default or null value)
@DocSvartz
Copy link

DocSvartz commented Jan 5, 2025

Hello @brgrz
Do you want to prevent null leaking from Source to Destination?

From this case:

  1. If null encountered, use a provided value (I know atm it uses default or null value)

Maybe it will help you Mapping with condition

@DocSvartz
Copy link

@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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants