AutoMapper: How to Initialize BindingFlags?

笑着哭i 提交于 2019-12-12 06:14:04

问题


When I asked this question about AutoMapper and protected properties, I received a response from Jimmy Bogard (AutoMapper co-creator). He suggested that we can initialize the BindingFlags using the code that I pasted below. The problem is, I get the following error and don't know how to fix it:

"AutoMapper.IConfiguration does not contain a definition for 'BindingFlags' and no extension method..."

Here's the code:

Mapper.Initialize(cfg =>
            {
                cfg.BindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
                cfg.CreateMap<PolicyDetail, Policy>();
            });

UPDATE:

I didn't have AutoMapper 3.3.0. Once I updated, this code worked. Thanks to Gert Arnold.


回答1:


Seems like it should work, looking at the source code, IConfiguration inherits from IProfileExpression, which inherits from IMappingOptions, which contains a public property with the following definition:

BindingFlags BindingFlags { get; set; }

See AutoMapper > src > UnitTests > BindingFlagsConfiguration.cs for an example to compare to what you have.



来源:https://stackoverflow.com/questions/27621464/automapper-how-to-initialize-bindingflags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!