AutoMapper:如何初始化BindingFlags? [英] AutoMapper: How to Initialize BindingFlags?
问题描述
当我问有关AutoMapper和protected
的问题时属性,我收到了 Jimmy Bogard (AutoMapper的共同创建者)的回复.他建议我们可以使用下面粘贴的代码初始化BindingFlags
.问题是,我收到以下错误,却不知道如何解决:
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不包含以下定义: 'BindingFlags',没有扩展方法..."
"AutoMapper.IConfiguration does not contain a definition for 'BindingFlags' and no extension method..."
代码如下:
Mapper.Initialize(cfg =>
{
cfg.BindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
cfg.CreateMap<PolicyDetail, Policy>();
});
更新:
我没有AutoMapper 3.3.0.更新后,此代码即可正常工作.感谢Gert Arnold.
I didn't have AutoMapper 3.3.0. Once I updated, this code worked. Thanks to Gert Arnold.
推荐答案
似乎应该起作用,查看源代码,IConfiguration
继承自IProfileExpression
,而IProfileExpression
继承自IMappingOptions
,其中包含公共属性具有以下定义:
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; }
请参见 AutoMapper> src> UnitTests> BindingFlagsConfiguration.作为示例与您的现有产品进行比较.
See AutoMapper > src > UnitTests > BindingFlagsConfiguration.cs for an example to compare to what you have.
这篇关于AutoMapper:如何初始化BindingFlags?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!