AutoMapper / AutoMapper.Extensions.Microsoft.DependencyInjection

MIT License
258 stars 79 forks source link

Destination object is null using ConvertUsing #155

Closed chialiyun closed 2 years ago

chialiyun commented 3 years ago

I have the following custom converter.

public class DocumentObjectConverter : ITypeConverter<DocumentObject, DocumentObject>
    {
        public DocumentObject Convert(DocumentObject source, DocumentObject destination, ResolutionContext context)
        {
            //destination = new DocumentObject(); // I have to manually create this but I would like to create the derived object.
            foreach (string prop in source.GetDynamicMemberNames())
            {
                destination[prop] = source[prop];
            }

            return destination;
        }
    }

This is how I configured:

          CreateMap<DocumentObject, DocumentObject>()
                .IncludeAllDerived()
                .ConvertUsing(new DocumentObjectConverter());

Expected Behavior: In DocumentObjectConverter, destination object has been created. So the Convert method, just does the conversion of the attributes.

lbargaoanu commented 2 years ago

https://docs.automapper.org/en/latest/Dynamic-and-ExpandoObject-Mapping.html

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.