How can I use AutoMapper on properties marked Internal?

前端 未结 3 512
借酒劲吻你
借酒劲吻你 2021-01-13 06:44

I have a solution with several projects. A business components project, an MVC web app, a DTO\'s and ViewModels project, a business component unit test project, and an MVC u

3条回答
  •  再見小時候
    2021-01-13 07:41

    Just set the ShouldMapProperty property of your configuration object in the initialize method.

    Here is an example using the static API, however, you should be able to achieve the same in a similar fashion by using the non-static API.

    Mapper.Initialize(i =>
    {
        i.ShouldMapProperty = p => p.GetMethod.IsPublic || p.GetMethod.IsAssembly;
        i.CreateMap();                
    });
    

    If you use a profile, this must go in the constructor:

    public class MyProfile : Profile
    {
        public MyProfile()
        {
            ShouldMapProperty = arg => arg.GetMethod.IsPublic || arg.GetMethod.IsAssembly;
    
            // The mappings here.
        }
    }
    

提交回复
热议问题