Dotnet-Boxed / Framework

.NET Core Extensions and Helper NuGet packages.
https://RehanSaeed.com
MIT License
723 stars 78 forks source link

Boxed.Mapping: Allow source to be null (and set destination to null if so) #711

Open Kazpers opened 5 months ago

Kazpers commented 5 months ago

Describe the feature

Currently the Boxed.Mapping.MapperExtensions.Map method specifically checks whether source == null and throws an ArgumentNullException if so. It would be nice if it instead followed .NET nullable rules, and allowed a null source if the mapper defined a nullable type as source. In that case the destination would obviously also simply be null.

Instead, you currently have to do a workaround like: "var result = source == null ? null : _mapper.Map(source)" on every line calling a mapper where the source is a nullable type.