是Automapper应该与私营制定者OOB工作? [英] Is Automapper supposed to work with private setters OOB?

查看:170
本文介绍了是Automapper应该与私营制定者OOB工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有公共属性与私人制定者一个嵌套的子类。在父类中,我能够使用Automapper映射到子类,并正在设置专用制定者的价值。我读过的一切指向Automapper不支持这一点,需要在子类的自定义构造函数来填充私人制定者。

I have a nested child class with public properties with private setters. In the parent class I am able to use Automapper to map to the child class and the values of the private setters are being set. Everything I've read points to Automapper not supporting this and requiring a custom constructor in the child class to populate private setters.

时使用反射或东西映射私营制定者当前的版本?的制定者肯定是私有的,因为在父类中,我无法集中Child.Property,但在同一个地方Mapper.Map能够设置属性。

Is the current version using reflection or something to map the private setters? The setters are definitely private because in the parent class I am unable set Child.Property but in the same place Mapper.Map is able to set the property.

推荐答案

Automapper 使用反射广泛,而且没有理由不使用它来设置私有制定者。

Automapper uses reflection extensively, and there is no reason not to use it to set private setters.

事实上,直到你的问题我不知道,它的作品。

Actually, until your question I didn't know that it works.

如果我们看一下单元测试中,我们可以发现,民营制定者自动设置的事实。请参阅<一href="https://github.com/AutoMapper/AutoMapper/blob/develop/src/UnitTests/Bug/AutoMapperInheritanceProblemDemo.cs"相对=nofollow> PrivateSetterInParentWorks

If we look at unit tests we can found the fact that private setters are set automatically. Please see PrivateSetterInParentWorks.

请注意,<一个href="http://stackoverflow.com/questions/7277108/access-to-private-method-using-reflection-in-c-silverlight-applications">Silverlight不支持通过反射设置私有字段。因此,该功能无法使用它。

Note, Silverlight doesn't support setting private fields through reflection. So, the feature doesn't work with it.

这篇关于是Automapper应该与私营制定者OOB工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆