How to map null to empty Array/List? #1251
-
Im porting over some Automapper mappings. AutoMapper will by default map a null value to empty container and not to a null value. Can I do this with Mapperly as well, and if so how? E.g. this AutoMapper code will print using System;
using System.Collections.Generic;
public class A { public IEnumerable<string> X { get; set; } }
public class B { public IEnumerable<string> X { get; set; } }
public class Program
{
public static void Main()
{
var config = new AutoMapper.MapperConfiguration(
cfg => {cfg.CreateMap<A, B>();});
var mapper = config.CreateMapper();
var a = new A();
var b = mapper.Map<B>(new A());
Console.WriteLine($"{a.X==null}, {b.X==null}");
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
latonz
Apr 26, 2024
Replies: 1 comment
-
You can use a user-implemented mapping method for this, see docs. Unfortunately, generic user-implemented mappings are not yet supported in Mapperly, see #451. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
viblo-majority
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use a user-implemented mapping method for this, see docs. Unfortunately, generic user-implemented mappings are not yet supported in Mapperly, see #451.