Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Why is the list collection mapping configuration invalid

Open ysq5202121 opened this issue 3 years ago • 1 comments

TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true); var config = new TypeAdapterConfig(); config.ForType<a, b>().IgnoreNullValues(true); List lista=new List(); List listb=new List(); var test1= input[0].Adapt(entity[0], config); var test2= input.Adapt(entity, config);

The first is correct. Null is not mapped The list set mapping directly maps null into it

Does not support mapping collection types????

ysq5202121 avatar May 19 '22 04:05 ysq5202121

I think it's because CollectionAdapter is not performing null check before add to collection

private Expression CreateListSet(Expression source, Expression destination, CompileArgument arg)
{
        //### IList<T>
        //for (var i = 0, len = src.Count; i < len; i++) {
        //  var item = src[i];
        //  dest.Add(convert(item));
        //}

        //### IEnumerable<T>
        //foreach (var item in src)
        //  dest.Add(convert(item));

devbased avatar May 19 '22 07:05 devbased