Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Automapper supposed to work with private setters OOB?

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.

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.

like image 374
Monstieur Avatar asked Oct 04 '22 22:10

Monstieur


1 Answers

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.

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

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

like image 102
mt_serg Avatar answered Oct 07 '22 20:10

mt_serg