You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In some cases it makes sense to allow/support nullable reference types in mapping methods.
As far as I can see, Mapperly does not use such methods if the target is not nullable.
Overloading both variants is not possible and would just be redundant code duplication anyway, so that is not an option.
Instead I suggest changing the code generation to use these methods
Declaration code
[Mapper(ThrowOnPropertyMappingNullMismatch=true)]publicstaticpartialclassMapper{publicstaticpartialATargetAToTarget(Aa);// this is not used by AToTarget[return:NotNullIfNotNull(nameof(b))]publicstaticpartialBTarget?BToTarget(B?b);// this would be used by AToTarget//public static partial BTarget BToTarget(B b);}publicclassA{publicBB{get;set;}}publicclassB{publicstring?Name{get;set;}}publicclassATarget{publicBTargetB{get;set;}}publicclassBTarget{publicstring?Name{get;set;}}
Currently Mapperly only uses user-implemented mappings if the types match exactly.
Overloading both variants is not possible and would just be redundant code duplication anyway, so that is not an option.
As a workaround: Instead of overloading you can create the method with the parameter types for Mapperly with another name and just call your existing method. The point made on code duplication obviously still applies...
If this is implemented, other nullable attributes need to be considered too (e.g. MayBeNullAttribute). See MS docs.
Describe the bug
In some cases it makes sense to allow/support nullable reference types in mapping methods.
As far as I can see, Mapperly does not use such methods if the target is not nullable.
Overloading both variants is not possible and would just be redundant code duplication anyway, so that is not an option.
Instead I suggest changing the code generation to use these methods
Declaration code
Actual relevant generated code
Expected relevant generated code
something like
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: